Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » eclipselink: generate entities without joins
eclipselink: generate entities without joins [message #1421351] Thu, 11 September 2014 08:50 Go to next message
G M is currently offline G MFriend
Messages: 3
Registered: July 2014
Junior Member
Two entities:

Customer <--- Account
 id             id
 name           customerId (FK to Customer)
                balance


eclipselink 'generate entities from tables' generates the two entity classes. `Customer` has reference to `Account` and vice versa.

    public class Customer {
      Integer id;
      String name;
      Account account;
    }

    public class Account {
      Integer id;
      Customer customer;
      Double balance;
    }


Required: Generate entities with relationship attribute as basic type instead of Entity name:

    public class Customer {
      Integer id;
      String name;
      Integer accountId; // <-- this is id instead of Account
    }

    public class Account {
      Integer id;
      Integer customerId;  // <-- this is id instead of Customer
      Double balance;
    }


Why we need this:
`Customer` and `Account` are managed by separate applications and hence packaged in separate wars. Each war may potentially be deployed on a separate app server. If the Customer application needs Account details, it will use the public API provided by Account application and does not read from DB directly. This is to avoid Customer application from modifying the Account entity by itself without the knowledge of Account application.

Eclipselink generation has an option to turn off relationship generation altogether. Is there a way to generate only the ids instead of entity class names? Or is there a better way to manage this?
Re: eclipselink: generate entities without joins [message #1425654 is a reply to message #1421351] Wed, 17 September 2014 16:32 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I'm not sure how to turn off building relationships in entities when generating Entities from tables, but you might try removing the foreign key constraints as I believe most entity generators look at these to determine object relationships.

What I wanted to point out though is that your design decisions will have a few problems. The relationship you are showing in the database has only 1 foreign key, customerId that exists in the Account table. That means that if customer is in its own war with no access to the Account table/entity, there is no way for the customer application to see anything about accounts. There can be no Integer accountId; field within the class as it is something that needs to be looked up and read from the account entity/table.

If you want to avoid one application making changes it shouldn't, you might try making the entity read-only https://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_readonly.htm This would allow both applications to reuse the same object model and database, but different orm.xml files for each would ensure they cannot mistakenly update the wrong entities.

Previous Topic:EclipeLink with Maven
Next Topic:Multiple JTA data sources for single PU
Goto Forum:
  


Current Time: Tue Mar 19 04:32:09 GMT 2024

Powered by FUDForum. Page generated in 0.01933 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top