-->
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.  [ 2 posts ] 
Author Message
 Post subject: Annotations and DM UML Aggreggation
PostPosted: Wed Nov 14, 2007 12:16 am 
Newbie

Joined: Wed Nov 14, 2007 12:05 am
Posts: 1
PERSON TABLE
---------------------
PERSON_ID -->PK


ADDRESS TABLE
--------------------
PERSON_ID --> PK from Person, FK to Person
ADDRESS_ID --> PK (1, 2, 3 ... for each person_id)

I have two questions:
1. How to implement the DB UML Aggregation model with hibernate annotations?
2. How to implement ADDRESS_ID increment that corresponds to this DML: select MAX(ADDRESS_ID) from ADDRESS where person_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 4:22 pm 
Newbie

Joined: Thu Nov 15, 2007 1:36 pm
Posts: 12
Location: Ahsburn, VA
I'd think you'd do something like:

Code:
@Entity
@Table( name="People" )
class Person {
    @Id @GeneratedValue
    @Column( name = "PERSON_ID" )
    private Long id;     // Surrogate Key for Hibernate

    @OneToMany( mappedBy = "parentPerson", cascade = CascadeType.ALL )
    @Cascade( org.hibernate.annotations.CascadeType.DELETE_ORPHAN )
    private List<Address> addresses = new ArrayList<Address>();
    // Remember to write your helpers!
}


And on the other side:
Code:
@Entity
@Table( name="Addresses" )
class Address {
    @Id @GeneratedValue
    @Column( name = "ADDRESS_ID" )
    private Long id;     // Surrogate Key for Hibernate

    @ManyToOne( targetEntity = Person.class )
    private Person parentPerson;
    // Remember to write your helpers!
}


And I suspect your HQL would look very close to:
"select MAX(id) from Address where parentPerson = :person_id"


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