Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to insert null value into my entity bean with a long type id?

 
Meng Xin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two beans called Group and Event.
A Group has an id and name. The id is a long type.
A Event has an id, title, and group which is Group type. A Event has a ManytoOne relationship with Group. A Event can only belong to one Group and a Group can have many Events. But A Events can also not belong to any Group.
My problem is I want to create a event with no group. I want to insert null into the mapping event table group_id column. Because the id property in Group is long, I can't set it to null. If I new Group(), the default id value is 0 not null. When I persist a Event with setGroup=new Group() into my event table, it gives me error because the group_id is 0 but this is no 0 id in my group table which is the foreign key.
How can I create a Event with no Group? I want insert null into the group_id column of my event table? Please help me.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just don't set a group in the event, the group reference will be null, and the foreign key will be null. Do not create an empty group.
 
Meng Xin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James! I'll try it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic