-->
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: Newbie component mapping problem? Not clear in documentation
PostPosted: Wed Jan 11, 2006 12:16 pm 
Newbie

Joined: Tue Jan 10, 2006 10:00 am
Posts: 5
I am trying to convert an existing application to hibernate for persistence so I want to initially map between the existing value objects and tables without having to refactor any java code.

I am having trouble with one concept in the value objects that is not represented in the reference guide clearly.

Many of the value objects have composite entities that are stored in different tables but those tables do not have a foreign key back to the containing object and nor should they as they don't necessarily refer always to the same class.

An example might make it clearer. There is an Address class and and address table. Many other classes have an address_id which indicate which row to load into the value object (by a kind of builder pattern in the data access logic). This way anything that has an address (company, client, user) has just an id and the builder fills in the Address object before returning results to the client. It does a similar operation in reverse when saving an object with an Address object inside it.

I want hibernate to fill in this composite address on load and update it in another table on save but not sure what to put in the XML so that takes place.. Suggestions appreciated..

public class Account
implements java.io.Serializable
{
// persisted
private int id;
private String firstName;
private String lastName;
private String description;
private String insurance_company;
private String insurance_policyNumber;
private Date insurance_expiryDate;
private String insurance_contactName;
private String insurance_contactPhoneNumber;
private boolean insurance_letterIndemnityReceived;
private String typeId;
private String company;
private int addressId; // <--- This indicates what to load into Address

// dynamic
private Address address;
private Driver[] drivers;
...
}

public class Address
implements java.io.Serializable {
private int id;
private String street1;
private String street2;
private String city;
private String county;
private String postCode;
private String phone1;
private String phone2;
...
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 1:49 pm 
Newbie

Joined: Tue Jan 10, 2006 10:00 am
Posts: 5
More info.. This is the kind of building going on that I want hibernate to handle instead.. An example from the builder logic on account that handles the constructed fields of the address and the driver array..

public int addAccount(Account account)
throws DAOException
{
// add address
int addressId = addAddress(account.getAddress());
account.setAddressId(addressId);

int id = getDAO().addAccount(account);

getDAO().removeAccountDrivers(id);
getDAO().addAccountDrivers(id, account.getDrivers());

notifyAdd(Account.class, id);
return 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.