| Author |
Leaving any property unmapped to a column in Hibernate using annotation
|
Mohammad Nabeeluddin Ansari
Greenhorn
Joined: Apr 20, 2011
Posts: 10
|
|
Hi,
When I am leaving any property lets say empId unmapped to any column of the table then I am getting SQLGrammarException exception.
I am using annotations intead of a Employee.hbm.xml file.
But I have read that you can leave some properties of yuor class unmapped.While saving the object of that class,only the mapped properties will be saved and the unmapped properties will be present in the insert query.
Regards:
Nabeel
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
Hey,
I think you can mark them with the @Transient annotation and this will make them ignored.
If you are still having problems though then post your entity code.
Sean
|
I love this place!
|
 |
Mohammad Nabeeluddin Ansari
Greenhorn
Joined: Apr 20, 2011
Posts: 10
|
|
I will try it tomorrow morning.
Another problem which I was having is:
I am using mysql DB.I have a table employee with empno as the PK.Now i set it to auto increment using an annotation.
Now when I tried to save an object of Employee class then the system gives an exception: The DB could not generate incremented value.
But when I changed the column in the employee table to auto increment then it worked properly.
I my question is not understandable to you then let me know,I will try to further explain it.
|
 |
Hemant Thard
Ranch Hand
Joined: Dec 23, 2008
Posts: 119
|
|
hi,
take a look at this
|
 |
Mohammad Nabeeluddin Ansari
Greenhorn
Joined: Apr 20, 2011
Posts: 10
|
|
Not working,I think auto key generation does not work with mysql unless the column in the table is set to Auto_Increment(then @GeneratedValue annotatino is also not required).
My code is something like this:
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="empno")
private int empNo;//empno is the PK in the table
|
 |
Sim Petro
Greenhorn
Joined: Apr 08, 2013
Posts: 1
|
|
Sean Clark wrote:Hey,
I think you can mark them with the @Transient annotation and this will make them ignored.
If you are still having problems though then post your entity code.
Sean
Hi, This works for me. Thanks
|
 |
 |
|
|
subject: Leaving any property unmapped to a column in Hibernate using annotation
|
|
|