Java Toplink Essential - Change entities tables at runtime

This is a discussion on Java Toplink Essential - Change entities tables at runtime within the JDBC JAVA forums in Framework and Interface Programming category; In my db there are some tables like TABLE1_2006 (ID, CODE, VOLUME) TABLE2_2007 (ID, CODE, VOLUME) TABLE3_2008 (ID, CODE, VOLUME) They are equal but have diffferent name. In fact these tables are created every year (as you can see). In this sense they use the same entity public class MyEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "ID", nullable = false) private Integer id; @Column(name = "CODE") private String code; @Column(name = "VOUME") private String volume; .... .... .... } I need to obtain different list of entities relative to all tables in the ...

Go Back   Application Development Forum > Framework and Interface Programming > JDBC JAVA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-10-2008, 04:23 AM
nicola
Guest
 
Default Java Toplink Essential - Change entities tables at runtime

In my db there are some tables like

TABLE1_2006 (ID, CODE, VOLUME)
TABLE2_2007 (ID, CODE, VOLUME)
TABLE3_2008 (ID, CODE, VOLUME)

They are equal but have diffferent name. In fact these tables are
created
every year (as you can see).
In this sense they use the same entity

public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID", nullable = false)
private Integer id;
@Column(name = "CODE")
private String code;
@Column(name = "VOUME")
private String volume;

....
....
....
}

I need to obtain different list of entities relative to all tables in
the same database;
can I change table name of my entity at runtime ?


Thanks

Nicola
Reply With Quote
  #2  
Old 09-10-2008, 05:52 PM
Martin Gregorie
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

On Wed, 10 Sep 2008 01:23:48 -0700, nicola wrote:

> In my db there are some tables like
>
> TABLE1_2006 (ID, CODE, VOLUME)
> TABLE2_2007 (ID, CODE, VOLUME)
> TABLE3_2008 (ID, CODE, VOLUME)
>
> They are equal but have diffferent name. In fact these tables are
> created
> every year (as you can see).
> In this sense they use the same entity
>
> public class MyEntity implements Serializable {
> private static final long serialVersionUID = 1L; @Id
> @Column(name = "ID", nullable = false) private Integer id;
> @Column(name = "CODE")
> private String code;
> @Column(name = "VOUME")
> private String volume;
>
> ...
> ...
> ...
> }
>
> I need to obtain different list of entities relative to all tables in
> the same database;
> can I change table name of my entity at runtime ?
>
>

Declare a view over all the tables and enquire on that.

But, why on earth use multiple tables? They don't do anything that a
single table with a YEAR column couldn't do while managing to make at
least one task more difficult as you've just demonstrated.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Reply With Quote
  #3  
Old 09-11-2008, 12:14 AM
Lew
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

nicola wrote:
>> In my db there are some tables like
>>
>> TABLE1_2006 (ID, CODE, VOLUME)
>> TABLE2_2007 (ID, CODE, VOLUME)
>> TABLE3_2008 (ID, CODE, VOLUME)


Martin Gregorie wrote:
> Declare a view over all the tables and enquire on that.
>
> But, why on earth use multiple tables? They don't do anything that a
> single table with a YEAR column couldn't do while managing to make at
> least one task more difficult as you've just demonstrated.


I feel suspicion when I read about inherited tables in a DBMS, such as in
Postgres. At first blush the OP's situation seemed to me like an
inherited-table scenario. I felt about as I might encountering an escaped
specimen from Dr. Moreau's island.

I used to feel that way about automated object-relational mapping (ORM)
packages, but JPA alleviates that. There is a dichotomy between the world
view of object-oriented programming and that of relational database
architecture. Inherited tables seem out of place to me - object-oriented
monstrosities in a data world. Multiple identical tables are like that also -
if the data structures are the same and have the same interpretation, that
argues for a single logical table. Martin's suggestion is spot on, and
completely harmonious with the data-world outlook.

I don't know of a term analogous to "normal form" (as in "third normal form")
for excessive splitting of tables into many tables; all the normal forms have
to do with insufficient splitting. Advances in the database world occur in
how to structure data - relations, normal forms, star schemae, foreign keys,
these are the building blocks of DBMSes as classes and objects are of O-O
programming.

How one structures data for a database is different from how one structures
objects for a program.

--
Lew
Reply With Quote
  #4  
Old 09-11-2008, 03:37 AM
nicola
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

Hi guys, thanks a lot for your answers.
I agree with you but my boss wants this solution.
He said "To much rows for one table...." [some thousands].
Maybe because we use H2 Database Engine although H2 has very
good performances.
I don't understand his "brain engine".

Thanks again.


Nicola

Reply With Quote
  #5  
Old 09-11-2008, 05:06 AM
RedGrittyBrick
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime


GG nicola wrote:
> Hi guys, thanks a lot for your answers.
> I agree with you but my boss wants this solution.
> He said "To much rows for one table...." [some thousands].
> Maybe because we use H2 Database Engine although H2 has very
> good performances.
> I don't understand his "brain engine".
>


I'd suggest creating a pair of test systems, one with a single table,
one with many. Write a program that populates each with the same large
set of randomly generated data, measure memory usage and performance for
some typical queries. I'd expect that the results will prove that a
single table works best. However if it doesn't, at least you have a
justification for making a more complex, more expensive (to develop) and
harder to maintain solution.

--
RGB
Reply With Quote
  #6  
Old 09-11-2008, 05:37 AM
nicola
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

On 11 Set, 11:06, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
wrote:
> GG nicola wrote:
> > Hi guys, thanks a lot for your answers.
> > I agree with you but my boss wants this solution.
> > He said "To much rows for one table...." [some thousands].
> > Maybe because we use H2 Database Engine although H2 has very
> > good performances.
> > I don't understand his "brain engine".

>
> I'd suggest creating a pair of test systems, one with a single table,
> one with many. Write a program that populates each with the same large
> set of randomly generated data, measure memory usage and performance for
> some typical queries. I'd expect that the results will prove that a
> single table works best. However if it doesn't, at least you have a
> justification for making a more complex, more expensive (to develop) and
> harder to maintain solution.
>
> --
> RGB


I'll try it thanks.
Reply With Quote
  #7  
Old 09-12-2008, 05:33 AM
nicola
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

The use of YEAR colum is the best way. Take this boss!

Thanks all.

Thats all folks.
Reply With Quote
  #8  
Old 09-14-2008, 06:16 PM
Arved Sandstrom
Guest
 
Default Re: Java Toplink Essential - Change entities tables at runtime

"Lew" <noone@lewscanon.com> wrote in message
news:cqWdnWKfq97dBlXVnZ2dnUVZ_rCdnZ2d@comcast.com. ..
[ SNIP ]
> I don't know of a term analogous to "normal form" (as in "third normal
> form") for excessive splitting of tables into many tables; all the normal
> forms have to do with insufficient splitting. Advances in the database
> world occur in how to structure data - relations, normal forms, star
> schemae, foreign keys, these are the building blocks of DBMSes as classes
> and objects are of O-O programming.

[ SNIP ]

I've seen this particular operation - splitting one table into many tables
based on the value of an attribute, and dropping that column - described as
"attribute splitting". As I understand it this violates Domain Key Normal
Form (DKNF), because not all of the logical decisions your program would
want to make are defined by the data.

I'm leery of any approach where domain information is captured only in the
names of files or database tables. Even when using flat files I'd still want
to have a header line with information like this.

If the boss absolutely wanted this kind of splitting I'd at least argue for
keeping a year column in each table, even if it's all the same value for
each table.

AHS


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:26 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.