-->
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: Problem with @IndexColumn
PostPosted: Thu Apr 05, 2012 1:43 pm 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:11 am
Posts: 31
I have a One-to-Many-Relation between Parent and Child with the following mapping.

Code:
@Entity
public class Parent {
   private List<Child> children;

   @OneToMany(mappedBy = "parent")
   @IndexColumn(name = "position")
   @Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
   public List<Child> getChildren() {
      return children;
   }
}


@Entity
public class Child {
   private Parent parent;

   @ManyToOne(optional = false)
   @JoinColumn(name = "mediaSequence_id", nullable = false)
   public Parent getParent() {
      return parent;
   }
}


This works fine and I get two tables parent and child. The position row in the child table is correctly filled by Hibernate.

Now I wanted to explicitly add a position attribute to the Child class as I need to know the childs position at some time. Therefore I changed Child to:

Code:
@Entity
public class Child {
   private Parent parent;
   private int position;

   @ManyToOne(optional = false)
   @JoinColumn(name = "mediaSequence_id", nullable = false)
   public Parent getParent() {
      return parent;
   }
   
   @Column(name="position")
   public int getPosition() {
      return position;
   }

   public void setPosition(int position) {
      this.position = position;
   }

}


Now the position is not saved any more, but stays 0 in the database. Is my mapping incorrect or can't you add such an attribute to the Child class? I have read hibernate doc "2.4.6.2.1. Bidirectional association with indexed collections", but it didn't help me out.

I am using Hibernate 3.3.1.


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.