解决JPA 注解开发 Myeclipse 2017 C9 出现没有发现持久化单元中定义的名为 问题

目录结构:

162637_Psew_3518854.png

注解 @GeneratedValue(generator = "xxxxx"):虽然有叉叉 但不影响结果

162812_bgcI_3518854.png

解决方法:

163219_c5IY_3518854.png

代码示例如下 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>

 

转载于:https://my.oschina.net/u/3518854/blog/1591041

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值