目录结构:
注解 @GeneratedValue(generator = "xxxxx"):虽然有叉叉 但不影响结果
解决方法:
代码示例如下 orm.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
<entity class="cn.leelei.web.entity.Users">
<table name="users">
</table>
<attributes>
<id name="id">
<generated-value strategy="TABLE" />
</id>
<basic name="userName">
<column name="uname" length="100" />
</basic>
<basic name="passWord">
<column length="100" />
</basic>
</attributes>
</entity>
代码示例如下 persistence.xml 文件:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
<!-- 添加实体对象 -->
<!-- <class>cn.leelei.web.entity.Users</class>
<class>cn.leelei.web.entity.Students</class>
<class>cn.leelei.web.entity.Orders</class> -->
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="xxxx" />
<property name="hibernate.connection.password" value="xxxx" />
<property name="hibernate.connection.url" value="jdbc:mysql://xxxxxx:3306/xxxx" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<!-- 连接池 -->
<property name="hibernate.c3p0.acquire_increment" value="2"></property>
<property name="hibernate.c3p0.max_size" value="10"></property>
<property name="hibernate.c3p0.min_size" value="5"></property>
<property name="hibernate.c3p0.idle_test_period" value="3000"></property>
</properties>
</persistence-unit>
</persistence>