Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Leaving any property unmapped to a column in Hibernate using annotation

 
Mohammad Nabeeluddin Ansari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mohammad Nabeeluddin Ansari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

take a look at this
 
Mohammad Nabeeluddin Ansari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic