|
Re: Change table name at runtime [message #537714 is a reply to message #537481] |
Thu, 03 June 2010 13:03 |
|
You can change the name of a classes table using the descriptor API.
ClassDescriptor.setTablesNames() (or getTables().clear(), setTableName())
You can access the descriptors using a SessionCustomizer or DescriptorCustomizer or through accessing the EclipseLink Session from the EntityManager.
You can only change the tables until the session is initialized/connected.
You can also add new descriptors at runtime, but can only have one descriptor per class per session.
You might consider having a subclass of Sale per year, or dynamically define a new session/EntityManagerFactory for each year, or dynamically generate a subclass and descriptor per year. You may wish to investigate EclipseLink's dynamic support.
James : Wiki : Book : Blog : Twitter
|
|
|
|
|
Re: Change table name at runtime [message #538485 is a reply to message #537481] |
Mon, 07 June 2010 17:59 |
|
Don't worry about sessions.xml, it is not used with JPA.
You can get a Session from an EclipseLink JpaEntityManager using getSession(), or using em.unwrap(Session.class).
You can add a SessionCustomizer to your persistence.xml using the "eclipselink.session.customizer" persistence unit property.
James : Wiki : Book : Blog : Twitter
|
|
|
|
|
|
Re: Change table name at runtime [message #540918 is a reply to message #537481] |
Thu, 17 June 2010 15:45 |
|
As I said, you should not change a descriptor's table names after login. It should be done before creating your EntityManagerFactory, such as in a SessionCustomizer. Since the descriptors are shared across all EntityManagers, changing them on the fly is a bad idea.
You could unprepare the descriptor's insertQuery (from its DescriptorQueryManager) to get the insert to reprepare the SQL with the new table name. But changing descriptors on the fly is not a good idea.
You could try creating an entire new EntityManagerFactory on the fly with the new descriptor, or create a subclass for each table and clone the descriptor to map the subclass with the new table, or investigate EclipseLink dynamic Entity support.
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.04034 seconds