File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one Entity for two Database Schemas

 
Ast Lavond
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

is it possible to use the same Entity for two Database Schemas?
Both Schemas ("schema" and "schemaHistory") are identical. The Database Schema "schema" contains all current data and "schemaHistory" all the data, which were archived.

Width JDBC, it’s no problem. But I like to use the defined Entities.
Can you tell the Entity Manager which Schema and DataSource he should use?
The @Table(schema=”…”) annotation is probably not needed?

Thanks!
lanvond

 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use two different persistence units and use XML for both or one to change the schema.
There is a default schema in the orm.xml, potentially you could use the same annotation and just give a mostly empty orm.xml with a different default schema.

Otherwise you may be able to use some vendor specific property if your JPA provider supports this.

If using EclipseLink you can set the tableQualifier for one persistence unit.

EclipseLink also supports history, so if enabled will maintain this history table for you and allow historical queries into it.
 
Ast Lavond
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…Many thanks for the information.
I use the reference implementation from jBoss as persistence provider.
A seam application runs on this Application Server. It’s a CRUD Application and users have the option to search for data in the database schema “xy”.

Now I would like to implement an extended search → user can also search for archived data on schema “xyHistory”. This is done at runtime.
The results are two Lists. List A contains the data from schema “xy” and List B contains the data from “xyHistory”.
In JDBC I would open two database connections….

Unfortunately I’m not as well familiar with JPA.
You could use two different persistence units and use XML for both or one to change the schema.


Can I switch to the other schema with persistence units at runtime?
It’s not enough to use a second entity manager?

There is a default schema in the orm.xml, potentially you could use the same annotation and just give a mostly empty orm.xml with a different default schema.


Sorry, I don’t understand this. At the moment there isn’t a orm.xml in my Project.
An example code would be very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic