0

i want to save diffenent tables in the same database using hibernate with Java. I am using one class and mainmethod for each table. however if i create one of these tables, all previous created other! table's entries are dropped. Is there a possibitlity to stop that behaviour?

Here the config:

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost:5432/Hibernatetest</property>
    <property name="connection.username">postgres</property>
    <property name="connection.password">password</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

    <mapping class="basePackage.Table1" />
    <mapping class="basePackage.Table2" />
    <mapping class="basePackage.Table3" />
    <mapping class="basePackage.Table4" />
    <mapping class="basePackage.Table5" />

</session-factory>

Nellieder
  • 13
  • 3
  • could you please post your hibernate configuration here? – Zeus Jan 05 '15 at 16:37
  • added the config, my Problem here is that if i for instance use a class to create table 1 and then use a different class with a different mainmethod to cerate table2, the values of table1 are lost – Nellieder Jan 05 '15 at 19:58

2 Answers2

0

in your hibernate configuration you might have set hbm.ddl.auto property to create . remove that line. See this for details

Community
  • 1
  • 1
ashkhn
  • 1,642
  • 1
  • 13
  • 18
  • Hey, thx yes tried that already however i am having some Problems with upgrade, and i am fine with the fact, that the table i actually address using the current class is dropped, just not all the other tables in the database – Nellieder Jan 05 '15 at 19:54
  • I meant that you should remove that line from your configuration file. – ashkhn Jan 05 '15 at 20:57
  • ah sorry, didn't think of that, did some testing, and for me it seems as the result would be the same as with upgrade, so it kinda works, but for functionality i would rather like the create Setting just that tables not currently addressed are not dropped. – Nellieder Jan 05 '15 at 22:31
0

ok, think i found a solution. I use now different hibernate configs for my different classes and load them as described here: How to load hibernate.cfg.xml from different location

Community
  • 1
  • 1
Nellieder
  • 13
  • 3