I created Entity using Spring Roo:
I then use mvn install to package the result to data.jarCode:project --topLevelPackage com jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT entity jpa --class ~.Timer --testAutomatically field string --fieldName message --notNull
Next, I create an Eclipse project and set dependency to the data.jar and try to use it as follow:
Spring config:Code:public class App { public static void main(String[] args) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "D:/Proj/applicationContext.xml"); Timer t = new Timer(); t.setMessage("msg"); Timer.entityManager().persist(t); } }
but I get error:Code:<?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <context:spring-configured/> <context:component-scan base-package="com"> <context:exclude-filter expression=".*_Roo_.*" type="regex"/> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> </context:component-scan> <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:file:d:/tmp/man/com;shutdown=true"/> <property name="username" value="usr"/> <property name="password" value="pwd"/> <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> <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="persistenceUnit"/> <property name="dataSource" ref="dataSource"/> </bean> </beans>
I need to create DAOs from command line (The reason I use Spring Roo) so I can use it on my project, stand-alone application with no Spring Roo. I can't see how Spring Roo can allow it.Code:Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: com.Timer at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:868) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) at $Proxy30.persist(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at $Proxy29.persist(Unknown Source) at com.App.main(App.java:17)
Removing Spring Roo may solve my problem but it is not an option because it involves manual task to click button on Eclipse.
Any help to solve the issue greatly appreciated. Thanks.


Reply With Quote