D
D
Denis Kostousov2012-09-30 08:20:30
Java
Denis Kostousov, 2012-09-30 08:20:30

Automating the saving of objects in the database?

Good day.
It is necessary to automate the recording of objects in the database. There are several POJOs. It is necessary to organize their recording in a relational database in such a way that the table name can be set from the program. If not for the last requirement, I would use JPA. Are there any frameworks that allow you to automate the process of writing inserts or something like that?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
G
gvsmirnov, 2012-09-30
@gvsmirnov

@Table(name = "table_name_goes_here")

Doesn't count as "the table name could have been set from the program"?

D
Denis Kostousov, 2012-09-30
@sandello

No. The name of the table depends on the current date.

S
serso, 2012-09-30
@serso

Another option I can think of would be to use a database synonym / alias: FOO would be an alias for FOO_JAN2010 until… you change the alias to point on FOO_FEB2010. I've never tested this, I don't know if it will suit your needs. But it's another idea.

O
Ololesha Ololoev, 2012-10-02
@alexeygrigorev

The following tricky solution came to mind:
In Hibernate, you can create a configuration using the Configuration class - and import mapping using addInputStream(InputStream xmlInputStream) , and at the same time generate mapping data using some template engine.

O
Ololesha Ololoev, 2012-10-02
@alexeygrigorev

As a lightweight solution, you can use JdbcTemplate

D
dborovikov, 2012-10-03
@dborovikov

Your task is not typical, I don’t think there is a ready-made one, write such a generator yourself. If you do not need to save the graph of objects, then the task is trivial. Otherwise, I would look for other solutions, for example, I would abandon the object graph.

R
relgames, 2012-10-05
@relgames

Why is this necessary? If the date changes, isn't it easier to create a DATE column and write the date there? And if you really want separate tables, you can create a View with DATE conditions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question