• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Class Generation

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic