| Author |
JPA Class Generation
|
Arockia Raj
Ranch Hand
Joined: Dec 08, 2006
Posts: 31
|
|
Hi All,
I am having following simple scenario
customer-->Account(relationship as one to many),
'CUST_ID' in Account Table represents the Customer for this account
when we generate JPA classes the Account class CUST_ID column is represented by customer Object.So to get customer id
i need to access customer object.For some cases i only need customerid.Is it possible to configure the tool to generate both
field(CUST_ID) and relationship field (Customer Object)
Generated Class
@Entity
@Table(name="ACCOUNT")
public class Account implements Serializable
{
@ManyToOne
@JoinColumn(name="CUST_ID")
private Customer customer;
Required Class
@Entity
@Table(name="ACCOUNT")
public class Account implements Serializable
{
@ManyToOne
@JoinColumn(name="CUST_ID")
private Customer customer;
@Column(name="CUST_ID")
private java.math.BigDecimal custId;
Regards
A.Raj
|
 |
T Mishra
Ranch Hand
Joined: Apr 04, 2006
Posts: 107
|
|
|
You can always do customer.getId() to get the id. Why would you have such a need ?
|
Thanks,
Tushar (SCJP 1.5)
|
 |
Arockia Raj
Ranch Hand
Joined: Dec 08, 2006
Posts: 31
|
|
T Mishra wrote:You can always do customer.getId() to get the id. Why would you have such a need ?
Hi Mishra,
Thanks for the reply.The reason we dont want to use customer.getId(),this call will trigger a subquery to fetch all the customer details internally.Considering the performance we dont want to do this, and prefer having id attribute directly so that we can take this value alone and will call Customer object when we need the complete customer object information.
Regards
Raj
|
 |
T Mishra
Ranch Hand
Joined: Apr 04, 2006
Posts: 107
|
|
this call will trigger a subquery to fetch all the customer details
No, not unless you set the fetch mode to join or subquery.
As per the entity mapping definition you've mentioned below, it does not have a fetch mode. This means that the associations are loaded using proxies. This is the default fetch mode. Since CUST_ID is the identifier, only the id of the customer is loaded into the persistent context.
With your generated entity mapping, it should just work as you expect.
|
 |
Arockia Raj
Ranch Hand
Joined: Dec 08, 2006
Posts: 31
|
|
Thanks a lot for explaining this....
T Mishra wrote:
this call will trigger a subquery to fetch all the customer details
No, not unless you set the fetch mode to join or subquery.
As per the entity mapping definition you've mentioned below, it does not have a fetch mode. This means that the associations are loaded using proxies. This is the default fetch mode. Since CUST_ID is the identifier, only the id of the customer is loaded into the persistent context.
With your generated entity mapping, it should just work as you expect.
|
 |
 |
|
|
subject: JPA Class Generation
|
|
|