Springframework.dao.InvalidDataAccessResourceUsageException hibernate.SQLGrammarException MySQLSyntaxErrorException
The error is basically saying that there isn't a field/column on PortfolioType
called portfoliotype_id
that it can find, because the field is actually called id
.
This is a basic error because your ID column name doesn't match what you've specified in your @JoinColumn
annotation.
Change the classes to the following and it should work.
public class Story implements TimesheetLoggable, LabelContainer, NamedObject, TaskContainer { /** other fields omitted for space **/ @ManyToOne(optional = true, targetEntity=PortfolioType.class) @JoinColumn(name="portfolioTypeId") private PortfolioType portfoliotype;}
Portfolio Type:
public class PortfolioType { @Id @GeneratedValue(strategy = GenerationType.AUTO) @XmlAttribute(name = "objectId") @Column(name="portfolioTypeId") private int portfolioTypeId; /** other fields omitted for space **/}
You need to make sure that the name
value in your @Column
annotation, matches the name
in your @JoinColumn
annotation. Which is why always using id
as your ID field name isn't a great idea.
Also, just a tip, putting these annotations on the setters, makes it much harder to read and work out what your relationships are. The usual convention is to to put these annotations on the field declarations.
Most commonly InvalidDataAccessResourceUsageException
is thrown when database access is restricted to Read-only mode and you are trying to perform any DML query.