Announcement Announcement Module
Collapse
No announcement yet.
java.lang.IllegalArgumentException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.IllegalArgumentException

    My entity vo looks as follow:
    Code:
    package wei.spring.jsf.vo;
    
    import java.io.Serializable;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    @Entity
    @Table(name = "SBB")
    public class Sachbearbeiter implements Serializable {
    	@Id
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	private long id;
    
    	private String name;
    
    	public Sachbearbeiter() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    
    	public Sachbearbeiter(String name) {
    		super();
    		this.name = name;
    	}
    
    	public long getId() {
    		return id;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    }
    The unit test looks as follow:
    Code:
    public class SachbearbeiterDaoImpl extends JpaDaoSupport implements SachbearbeiterDao{
    
    	public void delete(Sachbearbeiter sachbearbeiter) {
    		getJpaTemplate().remove(sachbearbeiter);
    	}
    
    	public List<Sachbearbeiter> findAll() {
    		return getJpaTemplate().find("select s from SBB s");
    	}
    
    	public List<Sachbearbeiter> findByName(String name) {
    		return getJpaTemplate().find("select s from SBB s where s.name = ?1",name);
    	}
    
    	public Sachbearbeiter save(Sachbearbeiter sachbearbeiter) {
    		getJpaTemplate().persist(sachbearbeiter);
    		return sachbearbeiter;
    	}
    
    }
    And the unit test looks as follow:
    Code:
    package wei.spring.jsf.test;
    
    import org.springframework.test.jpa.AbstractJpaTests;
    
    import wei.spring.jsf.dao.SachbearbeiterDao;
    import wei.spring.jsf.vo.Sachbearbeiter;
    
    public class ServiceIntegrationTest extends AbstractJpaTests{
    
    	public SachbearbeiterDao sachbearbeiterDao = null;
    
    	protected String[] getConfigLocations() {
    		return new String[] { "classpath:META-INF/dwspring2-service.xml" };
    	}
    	
    	protected void onSetUpInTransaction() throws Exception {
    		Sachbearbeiter sbb = new Sachbearbeiter("Thomas John");
    		sachbearbeiterDao.save(sbb);
    	}
    	
    	public void testModifySachbearbeiter(){
    		Sachbearbeiter sbb = sachbearbeiterDao.findAll().get(0);
    		assertEquals(sbb.getName(), "Thomas John");
    		System.out.println(sbb.getName());
    	}
    	
    	public SachbearbeiterDao getSachbearbeiterDao() {
    		return sachbearbeiterDao;
    	}
    
    	public void setSachbearbeiterDao(SachbearbeiterDao sachbearbeiterDao) {
    		this.sachbearbeiterDao = sachbearbeiterDao;
    	}
    }
    As I run the unit test I got the exception as follow. But when I change the @Table to @Table(name = "Sachbearbeiter"), i.e. the same as the vo name, it's ok. Why?

    ***************

    org.springframework.dao.InvalidDataAccessApiUsageE xception: An exception occured while creating a query in EntityManager; nested exception is java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
    Caused by: java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
    at oracle.toplink.essentials.internal.ejb.cmp3.Entity ManagerImpl.createQuery(EntityManagerImpl.java:194 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.orm.jpa.JpaTemplate$CloseSuppr essingInvocationHandler.invoke(JpaTemplate.java:40 0)
    at $Proxy8.createQuery(Unknown Source)
    at org.springframework.orm.jpa.JpaTemplate$9.doInJpa( JpaTemplate.java:307)
    at org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:191)
    at org.springframework.orm.jpa.JpaTemplate.executeFin d(JpaTemplate.java:158)
    at org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:305)
    at org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:301)
    at wei.spring.jsf.dao.impl.SachbearbeiterDaoImpl.find All(SachbearbeiterDaoImpl.java:17)
    at wei.spring.jsf.test.ServiceIntegrationTest.testMod ifySachbearbeiter(ServiceIntegrationTest.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154 )
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.access$001(AbstractAnn otationAwareTransactionalTests.java:47)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests$1.run(AbstractAnnotati onAwareTransactionalTests.java:115)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTest(AbstractAnnota tionAwareTransactionalTests.java:180)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTestTimed(AbstractA nnotationAwareTransactionalTests.java:153)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runBare(AbstractAnnota tionAwareTransactionalTests.java:111)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:174)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:254)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit 3TestReference.run(JUnit3TestReference.java:128)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
    Caused by: Exception [TOPLINK-8034] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EJBQLExceptio n
    Exception Description: Error compiling the query [select s from SBB s]. Unknown abstract schema type [SBB].
    at oracle.toplink.essentials.exceptions.EJBQLExceptio n.unknownAbstractSchemaType(EJBQLException.java:47 9)
    at oracle.toplink.essentials.internal.parsing.ParseTr eeContext.classForSchemaName(ParseTreeContext.java :148)
    at oracle.toplink.essentials.internal.parsing.SelectN ode.getClassOfFirstVariable(SelectNode.java:351)
    at oracle.toplink.essentials.internal.parsing.SelectN ode.getReferenceClass(SelectNode.java:339)
    at oracle.toplink.essentials.internal.parsing.ParseTr ee.getReferenceClass(ParseTree.java:452)
    at oracle.toplink.essentials.internal.parsing.ParseTr ee.adjustReferenceClassForQuery(ParseTree.java:88)
    at oracle.toplink.essentials.internal.parsing.EJBQLPa rseTree.populateReadQueryInternal(EJBQLParseTree.j ava:112)
    at oracle.toplink.essentials.internal.parsing.EJBQLPa rseTree.populateQuery(EJBQLParseTree.java:93)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.j ava:204)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.j ava:174)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.j ava:138)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.<init>(EJBQueryImpl.java:99)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.<init>(EJBQueryImpl.java:84)
    at oracle.toplink.essentials.internal.ejb.cmp3.EJBQue ryImpl.<init>(EJBQueryImpl.java:71)
    at oracle.toplink.essentials.internal.ejb.cmp3.Entity ManagerImpl.createQuery(EntityManagerImpl.java:189 )
    ... 39 more

  • #2
    I solved the problem myself. Though I define the table name as @Table(name = "SBB"), when I implement the SQL I have to use the name of the vo as the table name such as follow:

    Code:
    public List<Sachbearbeiter> findAll() {
    		return getJpaTemplate().find("select s from Sachbearbeiter s");
    	}

    Comment

    Working...
    X