• 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

one Entity for two Database Schemas

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic