-->
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.  [ 8 posts ] 
Author Message
 Post subject: OneToMany annotation
PostPosted: Wed Sep 16, 2009 9:26 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
i have 3 next classes, my problem is to create the OneToMany annotation.
The Problem is that the linked fields are from ItemPK and not the Item Class.
i'm trying to solve this problem for long time with no success at all.

My Error is:
Code:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(itemCrossReferences)]
   at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
   at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
   at org.hibernate.mapping.Property.isValid(Property.java:185)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
   ... 52 more


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

   private static final long serialVersionUID = 8635086262992868784L;

   @EmbeddedId
   public ItemPK itemPK;
   
   @OneToMany(mappedBy = "item")
   private Set<ItemCrossReference> itemCrossReferences;

   public void setItemCrossReferences(Set<ItemCrossReference> itemCrossReferences) {
      this.itemCrossReferences = itemCrossReferences;
   }

   public Set<ItemCrossReference> getItemCrossReferences() {
      return itemCrossReferences;
   }   
   
   @Column(name = "ITM_ITEM_NAME")
   private String itemName;

   @Column(name = "ITM_CATEGORY_CODE")
   private Integer modelId;

   @Column(name = "ITM_VALID_TO")
   private Date validTo;

   @Column(name = "ITM_ITEM_STATUS")
   private String status;

}

Code:
@Embeddable
public class ItemPK implements Serializable {

   private static final long serialVersionUID = -5177491823551943094L;
   
   @ManyToOne
   @JoinColumn(name = "ITM_COMP_ID", referencedColumnName = "CMP_COMPANY_ID")
   protected Company company;

   public Company getCompany() {
      return company;
   }

   public void setCompany(Company company) {
      this.company = company;
   }   

   @Column(name = "ITM_ITEM_CODE", nullable = false)
   private String itemCode;
           
               //Setter/Getter

}


Code:
@Entity
@Table(name = "ELC_REFERENCE")
public class ItemCrossReference {

   
   @ManyToOne
   @JoinColumns( {
          @JoinColumn(name = "REF_MANUF_REF_CODE", referencedColumnName = "ITM_ITEM_CODE"),
          @JoinColumn(name = "REF_MANUF_CMP_CODE", referencedColumnName = "ITM_COMP_ID") })
            protected Item manufItem;

           //Setter/Getter
}
   


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Wed Sep 16, 2009 1:05 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi assaf77,

I'm not sure if I get you right but I think that your ItemCrossReference probably requires some EmbeddedId of its own to be referenced by.

Check this out - this looks quite similar to your stuff:
http://forums.java.net/jive/message.jspa?messageID=180447

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Thu Sep 17, 2009 8:01 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
Yes, i dumped it on my post but it was there.
Code:

@EmbeddedId
   public ItemCrossReferencePK itemCrossReferencePK;


But this is not the problem.
you can also see that the llink you gave me, the quetion is still open, its been solved for OneToOne but not for OneToMany.
I'm totaly dont know how to progress.


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Tue Sep 22, 2009 3:03 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
Do you think i have to write my own custom annotation ?


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Wed Sep 23, 2009 7:24 am 
Beginner
Beginner

Joined: Wed Jul 09, 2008 5:34 am
Posts: 41
Location: Brno, Czech Republic
What's the version of Hibernate components you are using (Core, Annotations, EntityManager)? I tried an environment similar to yours and was able to make it work.


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Thu Oct 01, 2009 8:23 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
I user Hibernate versions -

Annotation : 3.4.0.GA
Entity Manager : 3.4.0.GA
Core: 3.3.0.SP1

Do you think its a problem with version ?


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Thu Oct 01, 2009 9:55 am 
Beginner
Beginner

Joined: Wed Jul 09, 2008 5:34 am
Posts: 41
Location: Brno, Czech Republic
Not sure. I tested with Core 3.3.2.GA, Annotations 3.4.0.GA and EntityManager 3.4.0.GA. Try to compare the below test code I did with what you have. Maybe it helps you find any misconfiguration :-)

Entities:

Code:
public class Company implements Serializable {

   private static final long serialVersionUID = -4335199016164914319L;

   @Column
   private String name;

   @Id
   @GeneratedValue
   @Column(name="CMP_COMPANY_ID")
   private Long id;
// plus getter and setters
}


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

   private static final long serialVersionUID = 2544712122905762520L;

   @EmbeddedId
   public ItemPk itemPK;

   @OneToMany(mappedBy = "manufItem")
   private Set<ItemCrossReference> itemCrossReferences;

   @Column(name = "ITM_ITEM_NAME")
   private String itemName;
// plus getters and setters
}


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

   private static final long serialVersionUID = -8140917261932033851L;

   @Id
   @GeneratedValue
   private Long id;

   @ManyToOne
   @JoinColumns( {
         @JoinColumn(name = "REF_MANUF_REF_CODE", referencedColumnName = "ITM_ITEM_CODE"),
         @JoinColumn(name = "REF_MANUF_CMP_CODE", referencedColumnName = "ITM_COMP_ID") })
   protected Item manufItem;
// plus getters and setters
}


Code:
@Embeddable
public class ItemPk implements Serializable {

   private static final long serialVersionUID = -5892611455551220560L;

   @ManyToOne
   @JoinColumn(name = "ITM_COMP_ID", referencedColumnName = "CMP_COMPANY_ID")
   protected Company company;

   @Column(name = "ITM_ITEM_CODE", nullable = false)
   private String itemCode;
// plus getters and setters
}


And this is the code for the test:
Code:
      EntityManager em = getEntityManager();
      
      em.getTransaction().begin();

      Company company = new Company();
      company.setName("ACME");
      em.persist(company);

      ItemPk pk = new ItemPk();
      pk.setCompany(company);
      pk.setItemCode("XYZ");

      Item item = new Item();
      item.setItemPK(pk);
      item.setItemName("Item name 1");
      em.persist(item);
      em.getTransaction().commit();

      em.getTransaction().begin();
      ItemPk pk2 = new ItemPk();
      pk2.setCompany(company);
      pk2.setItemCode("ZYX");

      ItemCrossReference xref = new ItemCrossReference();
      xref.setManufItem(item);
      Set<ItemCrossReference> xrefItems = new HashSet<ItemCrossReference>();
      xrefItems.add(xref);

      Item item2 = new Item();
      item2.setItemPK(pk2);
      item2.setItemName("Item name 2");
      item2.setItemCrossReferences(xrefItems);
      em.persist(item2);
      em.getTransaction().commit();

      em.close();


Top
 Profile  
 
 Post subject: Re: OneToMany annotation
PostPosted: Sun Oct 04, 2009 6:14 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
Thank you very much !!!
This time its working :)


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

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.