-->
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.  [ 4 posts ] 
Author Message
 Post subject: association annotations in an embeddable object
PostPosted: Thu Aug 02, 2007 3:32 am 
Newbie

Joined: Mon Jul 16, 2007 6:26 am
Posts: 13
Hi NG!

I want to use an embeddable object, that contains a collection (aka an association) to entity-objects.

This should work, because hibernate_annotations.pdf says:

"While not supported by the EJB3 specification, Hibernate Annotations allows you to use association annotations in an embeddable object (ie @*ToOne nor @*ToMany). To override the association columns you can use @AssociationOverride."

If I generate ddl with the hibernate-tool hbm2ddl, the ddl looks nice. (see bottom of posting). But the result of hibernate-tool hbm2hbmxml only shows:

<component name="personsDelegate" class="PersonsDelegate">
<!-- TODO -->
</component>

I would like to change to hbm2hbmxml-templates, but I do not know what to insert into the <component>-tags.

Any hint in the right direction?

Regards Berti


Appendix, the code:

I want to persist the entities Class A, Class B, Person and an Embedded Class PersonsDelegate. They look like this:



@Entity
public class A {

private PersonsDelegate personsDelegate;

public PersonsDelegate getPersonsDelegate() {
return personsDelegate;
}

public void setPersonsDelegate (PersonsDelegate personsDelegate) {
this.personsDelegate = personsDelegate;
}

// ...plus some other A-specifc properties
}

I've another class B that looks like class A, i.e. has also a property personsDelegate but it contains also other properties that differ from class A. The entity person ist just an bean holding the informations about a person.

PersonsDelegate looks like this:

@Embeddable
public class PersonsDelegate {

private List<Person> peoplesCollection = new ArrayList<Person>();

@OneToMany( fetch=FetchType.EAGER )
@Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
public List<Person> getPeoplesCollection () {
return peoplesCollection ;
}

public void setPeoplesCollection (List<People> peoplesCollection ) {
this.peoplesCollection = peoplesCollection ;
}

public void addPerson(Person Person) {
peoplesCollection.add(Person);
}

public void removePerson(Person Person) {
peoplesCollection.remove(Person);
}
}

The generated DDL:

create table Person (
id varchar(255) not null,
name varchar(255),
primary key (id)
// ...some other stuff
);

create table A (
id varchar(255) not null,
primary key (id)
// ...some other stuff
);

create table B (
id varchar(255) not null,
primary key (id)
// ...some other stuff
);


create table A_Person (
A_id varchar(255) not null,
peoplesCollection_id varchar(255) not null,
unique (peoplesCollection_id)
);

create table B_Person (
B_id varchar(255) not null,
peoplesCollection_id varchar(255) not null,
unique (peoplesCollection_id)
);


alter table A_Person
add constraint FK2443D9E7C5183B47
foreign key (A_id)
references A;

alter table A_Person
add constraint FK2443D9E7A6B94834
foreign key (peoplesCollection_id)
references A;


alter table B_Person
add constraint FK2443D9E7C5183B47
foreign key (B_id)
references B;

alter table B_Person
add constraint FK2443D9E7A6B94834
foreign key (peoplesCollection_id)
references B;

The generated mapping-files look like this:

<!-- Generated 01.08.2007 11:21:48 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="A" table="A" lazy="false">
<id name="id" type="java.lang.String">
<column name="id" />
<generator class="uuid"></generator>
</id>
<component name="personsDelegate" class="PersonsDelegate">
<!-- TODO -->
</component>

<!-- ...plus some other mappings -->

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 4:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why are you generating mapping files when you already have annotations ?

ask for mapping advice in either user or ejb3/jpa forum.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 6:13 am 
Newbie

Joined: Mon Jul 16, 2007 6:26 am
Posts: 13
Good point!

My target platform is JDK 1.4 only, so I can't use annotations in it.
So I create mapping-files out of the annotated classes and use them instead.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 7:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok - but the conversion is not/won't be 100%

feel free to submit patches to improve it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.