Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Suresh K Babu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you Marco
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!