RooEntity 未映射
我正在使用 SpringRoo 来处理实体对象的休眠。
但是,在运行单元测试时,它们会失败,因为它表示实体未映射:
这是错误:
QuerySyntaxException:优惠券未映射 [SELECT o FROM COUPON o] 在 org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
这就是我的持久性单元的配置方式:
<persistence-unit name="persistenceUnitTest" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>
</properties>
</persistence-unit>
这就是我的实体的定义方式:
@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "COUPONID", identifierType = Integer.class, table = "COUPON")
public class Coupon {
设置了应用程序上下文:
<context:component-scan base-package="com.tamiflu.entities">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
</context:component-scan>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnitTest"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:tamiflu"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
</bean>
我觉得我有一切就位。我不知道为什么 @RooEntity 没有被拾取为正在映射。
I'm using SpringRoo to handle the Hibernation of my entity objects.
But when running unit tests, they are failing because it says the entity is not mapped:
Here is the error:
QuerySyntaxException: COUPON is not mapped [SELECT o FROM COUPON o]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
This is what my persistence unit is configured like:
<persistence-unit name="persistenceUnitTest" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>
</properties>
</persistence-unit>
This is how my entity is defined:
@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "COUPONID", identifierType = Integer.class, table = "COUPON")
public class Coupon {
The application context is set:
<context:component-scan base-package="com.tamiflu.entities">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
</context:component-scan>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnitTest"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:tamiflu"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
</bean>
I feel like I have everything in place. I don't know why the @RooEntity isn't being picked up as being mapped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mikko Maunu 是对的,您的 SELECT 对于 JPA 不正确,正确的是 SELECT o FROM Coupon o。
@RooJpaActiveRecord 是即将发布的 Roo: 1.2 版本(当前为 RC1)的新注释,@Entity 是当前 1.1.5 及之前版本 Roo 的注释。
如果问题仍然存在:
第二点的注释:Roo 创建使用通配符加载应用程序上下文文件的代码。
如果您有多个文件,请务必小心,因为无法保证顺序(如果您有多个包含不同包的文件要扫描,则加载实体时会遇到问题,除非您强制删除通配符并手动指定所需的顺序) applicationContext.xml 文件)
Mikko Maunu is right, your SELECT is not correct for JPA, the correct one is SELECT o FROM Coupon o.
@RooJpaActiveRecord is the new annotation for the incoming release of Roo: 1.2 (currently in RC1), and @Entity is the one for the current 1.1.5 and previous versions of Roo.
If the problem persists:
A note for the second point: Roo creates code that loads the application context files using wild cards.
Be careful if you have more than one, because the order is not guaranteed (if you have several files with different packages to scan, you will have issues loading entities, unless you force the order removing the wild cards and manually specifying the desired order for the applicationContext.xml files)