persistence.xml 4.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<persistence
    version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
    http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    
    <!-- 
         The <code>persistence.xml</code> file configures at least one persistence unit;
         each unit must have a unique name.
    -->
    <persistence-unit name = "strategy_drop-and-create">
        
        <!-- 
            Hibernate will scan your classpath for mapped classes and add them automatically
            to your persistence unit.
        -->
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        
        <!-- 
            setting the previous option "exclude-unlisted-classes" to 'true' requires entity classes to
22
            be listed explicitly. You may want to uncomment the following definition and add more classes.
23 24 25 26 27 28 29 30 31 32 33 34 35

            <class>sda1.Airline</class>
        -->
        
        <!-- 
            Standard or vendor-specific options can be set as properties on a persistence unit.
            Any standard properties have the <code>javax.persistence</code> name prefix, Hibernate's
            settings use <code>hibernate</code>
        -->
        <properties>
            <!-- 
                JDBC database connection parameter
            -->
36 37
            <property name = "javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name = "javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/hdm"/>
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
            <property name = "javax.persistence.jdbc.user" value="hdmuser"/>
            <property name = "javax.persistence.jdbc.password" value="XYZ"/>
            
            <!-- 
                The JPA engine should drop and re-create the SQL schema in the database
                automatically when it boots. This is ideal for automated testing, when
                you want to work with a clean database for every test run.
            -->
            <property
                name = "javax.persistence.schema-generation.database.action"
                value="drop-and-create"/>
            
            <!-- 
                When printing SQL in logs, let Hibernate format the SQL nicely and generate
                comments into the SQL string so we know why Hibernate executed the SQL statement.
            -->
            <property name = "hibernate.show_sql" value = "true" />
            <property name = "hibernate.format_sql" value="true"/>
            <property name = "hibernate.use_sql_comments" value="true"/>

58
            <property name = "hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect" />
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
            
            <!-- Enable Hibernate scanning for entity classes and adding them automatically
                but not for hbm.xml files. -->
            <property name = "hibernate.archive.autodetection" value="class"/>

        </properties>
    </persistence-unit>
    
    <!-- The subsequent persistence unit won't modify the database's schema 
        javax.persistence.schema-generation.database.action=none
        -->
    <persistence-unit name = "strategy_none">
        
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        
        <properties>
75 76
            <property name = "javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name = "javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/hdm"/>
77 78 79 80 81 82 83 84 85 86
            <property name = "javax.persistence.jdbc.user" value="hdmuser"/>
            <property name = "javax.persistence.jdbc.password" value="XYZ"/>
            
            <property
                name = "javax.persistence.schema-generation.database.action"
                value="none"/>
            
            <property name = "hibernate.show_sql" value = "false" />
            <property name = "hibernate.format_sql" value="true"/>
            <property name = "hibernate.use_sql_comments" value="true"/>
87

88 89 90 91 92 93
            <property name = "hibernate.archive.autodetection" value="class"/>
            
        </properties>
    </persistence-unit>
    
</persistence>