1

I have a persistence unit like this:

  <persistence-unit name="persistence Unit"
        transaction-type="JTA">     
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>com.example.User</class>
        <class>com.example.Team</class>
        <exclude-unlisted-classes />

        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update" /> 
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
            <property name="hibernate.connection.charSet" value="UTF-8" />
            <!-- JTA stuff -->
            <property name="hibernate.transaction.manager_lookup_class"
                value="org.hibernate.transaction.BTMTransactionManagerLookup" />
        </properties>               
    </persistence-unit>

When the server loads first time, this creates table for User and Team, but i dont want to create a table for Team. Is it possible?

Some settings in the persistence table maybe?

Magnilex
  • 11,584
  • 9
  • 62
  • 84
user1224036
  • 988
  • 1
  • 15
  • 34
  • I don't think it is possible. Why do you even want this? Hibernate needs the tables, or it will throw an exception during startup. And as you use update, `Team` won't be touched if it already exists. – Magnilex Jul 04 '13 at 09:56
  • Yes, i understand in normal circumstances i would not want to do this.However, i have opensource framework, which creates tables if its not there, so i dont want tables to be created by this persistence unit, Because it gets excecuted by the opensource as a routine startup, how ever i have additional custom classes like user . which i want to create. – user1224036 Jul 04 '13 at 09:59
  • So why do you need it? Do you want to create the table by a separate script or something? – Magnilex Jul 04 '13 at 10:00
  • I see. As far I know, no it is not possible by using `hibernate.hbm2ddl.auto`. – Magnilex Jul 04 '13 at 10:33
  • In this blog post, SchemaFilter is used for that: https://medium.com/@horiaconstantin/excluding-hibernate-entities-from-auto-generation-bce86f8e6d94 – Chris Aug 14 '19 at 09:08

2 Answers2

0

If table Team isn't changed (INSERT or UPDATE) by your application in any way, you could remove write permissions for it in your database system.

Tomestos
  • 48
  • 8
-1

Exclude Team class from your persistance.xml Remove following line.

<class>com.example.Team</class> 
Masudul
  • 21,823
  • 5
  • 43
  • 58