A good example of learning CDI

The example comes from: http://www.ibm.com/developerworks/cn/java/j-lo-cdijpa/

A good study example, a relatively complete introduction to CDI, is very beneficial for beginners. I have readjusted the example of the original text for everyone to download and study. Please go to the group (CDI (Weld) SPRING 32236089) to discuss and study.

1. Use the database javaDB that comes with java for testing The
advantage is that there is no need to configure an external database
1. Specify a javaDB database location, in this example: F:\YcApp\javaDB, database name: test, password: test, account: test , the configuration file is: /src/main/resources/META-INF/persistence.xml
2. Copy the jdk8 installation location\db\lib\derby.jar to the WEB-INF/lib of the project, (the 8U102 version has been copied 3. The
javaDB time format requirements are more strict, and the data in src/main/resources/sql/populate.sql is modified to '2010-06-01 10:00:00'

    <persistence-unit name="users">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>cn.jhc.bean.Employee</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
            <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
            <property name="hibernate.connection.url" value="jdbc:derby:F:\YcApp\javaDB\test;create=true;user=test;password=test" />
            <property name="hibernate.connection.password" value="test"></property>
            <property name="hibernate.connection.username" value="test"></property>
            <property name="hibernate.default_schema" value="test"></property>
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.import_files" value="/sql/populate.sql"/>
        </properties>
    </persistence-unit>
   
    II 、Configure using other data sources
   
    If you use mysql, change the previous item to mysql, and change the configuration information to:

    <persistence-unit name="users">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    < class>cn.jhc.bean.Employee</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/test" />
            <property name="hibernate.connection.password" value="rootps"></property>
            <property name="hibernate.connection.username" value="root"></property>
            <property name="hibernate.default_schema" value="test"></property>
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.import_files" value="/sql/populate.sql"/>
        </properties>
    </persistence-unit>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680120&siteId=291194637