-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Not saving FK's to database
PostPosted: Mon Jan 03, 2011 8:03 am 
Newbie

Joined: Mon Jan 03, 2011 7:51 am
Posts: 1
Hello,

Im trying to save a simple @OneToMany reference to the database. It saves al the data but it doesn't save the FK's. My code looks like this:
Code:

@Entity
@Table(name = "workweek")
public class WorkWeek extends BaseEntity {

   private static final long serialVersionUID = -1601661198784559768L;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;

   @Column(name = "weekNr", nullable = false)
   private Integer weekNr;

   @ManyToOne
   private Person worker;

   @OneToMany(mappedBy = "workweek", cascade = CascadeType.ALL)
   private List<WorkDay> workdays;
        ....

@Entity
@Table(name = "workday")
public class WorkDay extends BaseEntity {

   private static final long serialVersionUID = 7993536462165923057L;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;

   @Column(name = "date", nullable = false)
   private Date date;

   @ManyToOne
   @JoinColumn(name = "workweek_id")
        private WorkWeek workweek;
        .....


When I run a test, the db contains a workweek and several workdays but the reference to workweek is null. I generate the MySQL database from the code using hibernate.hbm2ddl.auto. The reference from workweek to worker is saved properly. I can also see in the logging that the week is saved before the workday but the reference to the workweek isnt saved in the workday.

Can anyone tell me what I'm doing wrong?

Thanks in advance!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.