Announcement Announcement Module
No announcement yet.
Unable to use Entity created using Spring Roo Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to use Entity created using Spring Roo

    I created Entity using Spring Roo:

    project --topLevelPackage com
    jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT  
    entity jpa --class ~.Timer --testAutomatically
    field string --fieldName message --notNull
    I then use mvn install to package the result to data.jar

    Next, I create an Eclipse project and set dependency to the data.jar and try to use it as follow:

    public class App {
    public static void main(String[] args) {
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
        Timer t = new Timer();
    Spring config:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="" xmlns:aop="" xmlns:context="" xmlns:jee="" xmlns:tx="" xmlns:xsi="" xsi:schemaLocation="">
    <context:component-scan base-package="com">
        <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
        <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
    <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 class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <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"/>
    but I get error:

    Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: com.Timer
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(
    at $Proxy30.persist(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(
    at $Proxy29.persist(Unknown Source)
    at com.App.main(
    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.

    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.

  • #2
    Create from Roo a multi module project with entities in a submodule.

    Then, analyze how Spring Roo is configuring the submodule into the parent module.

    Regards !


    • #3
      Brilliant, Spring Roo rocks, you rock.

      Just for everyone's benefit, I use the following standalone test code within mvc:
      package com.example.petclinic.ui.mvc;
      import java.util.*;
      import plicationContext;
      public class MyTest {
      public static void main(String[] args) throws Exception {
      ClassPathXmlApplicationContext context =
      new ClassPathXmlApplicationContext("classpath*:META-INF/spring/applicationContext*.xml");

      for (long i=0; i<10; i++) {
      Owner owner = new Owner();
      owner.setBirthDay(new Date());

      System.out.println("Total owners:"+Owner.countOwners());


      To test this, you need to run the above once then before second run you need to change core's persistense.xml:
      <!--<property name="" value="update"/>-->
      and (if not run as server data will be lost when MyTest ends):
      you run your hsqldb server: c:\hsqldb\bin>runServer.bat --database.0 file:d:/tmp/data/mydb --dbname.0 xdb