-->
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: Entity1 with OneToMany Entity2 is inserted last
PostPosted: Mon Sep 02, 2013 4:54 am 
Newbie

Joined: Fri Feb 01, 2013 2:51 pm
Posts: 3
I am using hibernate 4.1.9.
I am getting weird behavior from it.

This is what I have:


Code:
@Entity
@Table(name = "Container")
public class Container implements Serializable {

   private Integer containerID;
   private Set<ContainerIdentifier> containerIdentifiers;

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(unique = true, nullable = false)
   public Integer getContainerID() {
      return this.containerID;
   }

   public void setContainerID(Integer containerID) {
      this.containerID = containerID;
   }

   @OneToMany(mappedBy = "container", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
   public Set<ContainerIdentifier> getContainerIdentifiers() {
      return this.containerIdentifiers;
   }

   public void setContainerIdentifiers(
         Set<ContainerIdentifier> containerIdentifiers) {
      this.containerIdentifiers = containerIdentifiers;
   }
}



Code:
@Entity
@Table(name="ContainerIdentifiers")
public class ContainerIdentifier implements Serializable {

   private Integer containerIdentifiersID;
   private Container container;

   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(unique=true, nullable=false)
   public Integer getContainerIdentifiersID() {
      return this.containerIdentifiersID;
   }

   public void setContainerIdentifiersID(Integer containerIdentifiersID) {
      this.containerIdentifiersID = containerIdentifiersID;
   }

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name="containerID", nullable=false)
   public Container getContainer() {
      return this.container;
   }

   public void setContainer(Container container) {
      this.container = container;
   }
}


For some reason hibernate inserts first the ContainerIdentifiers and fails on non-null transient entity Container instead of starting with the Container.

Any clues?

Thanks


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.