-->
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: @OneToOne in @Embedded element
PostPosted: Tue Sep 20, 2005 10:22 am 
Newbie

Joined: Tue Sep 20, 2005 9:00 am
Posts: 5
Location: Austria
I am trying to map two embeddable objects with a reference to another object (see code) using an existing database:
Code:
@Entity(access=AccessType.FIELD)
public class Article {
   @Id
   String artnr;
   //...more defs
}

@Embeddable(access = AccessType.FIELD)
public class Unit {
   @OneToOne
   @JoinColumn(name="unit_artnr",referencedColumnName="artnr")
   Article article;
   Integer amount;
   //... more defs
}

@Entity(access = AccessType.FIELD)
public class Order {
   @Embedded
   @AttributeOverrides({
         @AttributeOverride(name="article",column=@Column(name="bunit_artnr")),
      @AttributeOverride(name="amount",column=@Column(name="bunit_amount"))
   })
   Unit bunit;
   @Embedded
   @AttributeOverrides({   
         @AttributeOverride(name="article",column=@Column(name="lunit_artnr")),
      @AttributeOverride(name="amount",column=@Column(name="lunit_amount"))
   })
   Unit lunit;
}

The code should finally boil down to this table:
Code:
Table Order
   -- ...
   bunit_artnr varchar(10),
   bunit_amount integer,
   lunit_artnr varchar(10),
   lunit_amount integer,
   -- ...

Instead of this I get the following error from hibernate:
Code:
   INFO: processing foreign key constraints
org.hibernate.MappingException: Repeated column in mapping for entity: com.softworks.pronto.model.Order column: unit_artnr (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:550)

As far as I can tell the field name is not correctly substituted when the element is a @OneToOne.
I can remove lunit, leaving only the single reference to bunit, in which case the generated sql is incorrect unless I modify the @JoinColumn in Unit to
Code:
   @JoinColumn(name="bunit_artnr")

but this is counterproductive and not what I intend to do.

Any ideas on how to fix this?

Version Info: annotation-3.1b5

_________________
Richard Schwaninger


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 5:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/329.html#A3

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 2:25 am 
Newbie

Joined: Tue Sep 20, 2005 9:00 am
Posts: 5
Location: Austria
Is there a chance that these annotations will be implemented in the near future? Embedded objects are nearly useless without them and I have to add a lot of complexity to my code when working around it.

Another "nice-to-have" would be @Version in an @Embeddable.

Thanks for your help.

_________________
Richard Schwaninger


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 6:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I guess I need to work on that sooner or later

But what's the use case for @Version in an @Embeddable?
I not even sure H3 core support that, doesn't really make sense to me.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 8:50 am 
Newbie

Joined: Tue Sep 20, 2005 9:00 am
Posts: 5
Location: Austria
Make it sooner, it would help me a lot. Thanks in advance.

concerning @Version
Code:
@Embeddable(access=AccessType.FIELD)
public class History {
   Timestamp createDate;
   @Version
   Timestamp changeDate;
   //...
}

@Entity(access = AccessType.FIELD)
public class Article {
   //...
   @Embedded
   History history;
}
@Entity(access = AccessType.FIELD)
public class Order {
   //...
   @Embedded
   History history;
}

This way I have version info in all my Objects without subclassing. My need comes from a legacy database that could be easily modelled in hibernate with that construct (I didn't try this with h3 core, only with annotations, so I don't know if it works there).

_________________
Richard Schwaninger


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 11:19 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Components don't have versions.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 2:29 am 
Newbie

Joined: Tue Sep 20, 2005 9:00 am
Posts: 5
Location: Austria
I don't see @Embeddable as a component, to me it is merely a boilerplate to construct part of an object.
As mentioned in my example above I have an existing database and try to reverse engineer that with ejb. The example corresponds to these tables:
Code:
Table Article
   id integer,
   ...
   createDate timestamp,
   changeDate timestamp

Table Order
   id integer,
   ...
   createDate timestamp,
   changeDate timestamp


The original database was created by a perl script that used such templates extensively to ensure consistent fields for all tables. Using @Embeddable does just this. Now changeDate is my only possible candidate for the version info so I would like to model that with @Version.

_________________
Richard Schwaninger


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So use @EmbeddableSuperclass and technical inheritance.

_________________
Emmanuel


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.