Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Class Generation

 
Arockia Raj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always do customer.getId() to get the id. Why would you have such a need ?
 
Arockia Raj
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic