jpa注解的一个小问题 在学习jpa注解在实体类上报这个错,但是运行起来却没有错Class "org.lw.jpa.entity.Person" is mapped, but is not included in any persistence unit这是什么原因呢?是编译器还是什么呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在resources的persistence.xml文件中类似于;<persistence 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" version="1.0"> <persistence-unit name="visitorPU" transaction-type="RESOURCE_LOCAL"> <class>com.cybersoft4u.example.domain.Visitor</class> <class>com.cybersoft4u.example.domain.Comment</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> --> </properties> </persistence-unit></persistence> 嗯,谢谢,我刚开始注意了这个问题,但是我是这样的,它报错:<?xml version="1.0" encoding="UTF-8"?><persistence 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" version="1.0"> <persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL"> <properties> <property name = "hibernate.connection.driver_class" value = "com.mysql.jdbc.Driver"/> <property name = "hibernate.connection.url" value = "jdbc:mysql://localhost:3306/jpa"/> <property name = "hibernate.connection.username" value = "root"/> <property name = "hibernate.connection.password" value = "root"/> <property name="hibernate.connection.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> <class>org.lw.jpa.entity.Person</class> </persistence-unit> </persistence>看来class只能放在properties的上面呀,是这样的吗? 其实,<properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> --> </properties>这段,不要放在这个文件里面。因为一般dataSource都在别的地方配置,最好是一个独立的xml中。 嗯,放在spring配置文件中也可以。 在请求完页面上取值 在JDK1.5上面实现CORBA服务,由Delphi客户端调用 昨天项目还能跑通,今天就不行啦 有谁用过lucene吗,如果我想做文字高亮,那建索引的时候,是不是需要存储那个文字字段 请教高手,Linux下war包发布提示找不到文件(而文件存在)出错,如何解决? 请教教小弟:读取 txt文件,并插到数据库!!! 关于jboss部署ejb问题, jboss4.01如何配置 用eclipse+lomboz+jboss开发ejb,generate ejb classes出错 求:全文检索工具 struts2的action之间怎么穿参数呢? 能不能在内部类中创建外部类的对象?
类似于;<persistence 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"
version="1.0">
<persistence-unit name="visitorPU" transaction-type="RESOURCE_LOCAL">
<class>com.cybersoft4u.example.domain.Visitor</class>
<class>com.cybersoft4u.example.domain.Comment</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
</properties>
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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" version="1.0">
<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
<properties>
<property name = "hibernate.connection.driver_class" value = "com.mysql.jdbc.Driver"/>
<property name = "hibernate.connection.url" value = "jdbc:mysql://localhost:3306/jpa"/>
<property name = "hibernate.connection.username" value = "root"/>
<property name = "hibernate.connection.password" value = "root"/>
<property name="hibernate.connection.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
<class>org.lw.jpa.entity.Person</class>
</persistence-unit>
</persistence>
看来class只能放在properties的上面呀,是这样的吗?
其实,<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
</properties>这段,不要放在这个文件里面。因为一般dataSource都在别的地方配置,最好是一个独立的xml中。
嗯,放在spring配置文件中也可以。