Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Can we declare same entity in two or more persistence units?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am newbie to JPA,

I have a question on use of entities in between different entities.

Q: Is it valid to share a single or more entities among two or more persistence units as given below for CommonEntity.
<persistence>
<persistence-unit name = "actionBazaar">
<class>ejb3inaction.persistence.Category</class>
<class>ejb3inaction.persistence.Bid</class>
<class>ejb3inaction.persistence.CommonEntity</class>
...
</persistence-unit>
<persistence-unit name = "humanResources">
<class>ejb3inaction.persistence.Employee</class>
<class>ejb3inaction.persistence.Department</class>
<class>ejb3inaction.persistence.CommonEntity</class>
....
</persistence-unit>

If so, Is there any consideration need to be taken while using this kind of entities and persistence-units

Can any one please provide me this information.

Thanks,
Suresh
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ksuresh,

one easy way would be to try it out

Without knowing the answer exactly I'm pretty sure it IS possible. After all regarding persistence an entity basically defines just your O/R mapping. And I think it would be too uncommon to have an application which uses the same mapping for more than one persistence unit/database. Therefore I can't see any good reason why it should not be possible. In the end the target database is defined by the EntityManager you use and so the entity itself shouldn't even care about multiple PUs.

Marco
 
Suresh K Babu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Marco
 
That feels good. Thanks. Here's a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic