Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Undetected problem mapping fields to columns

For now, I prefer to go deap before assuming this is a bug! Perhaps I miss
something!

Perhaps exposing the problem in other terms is enough...

Assume AbstractEvent an abstract class representing the root of the
hierarchy of entities.
----------------------------
package problem;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "EVENT_TYPE")
public abstract class AbstractEvent
{
	@Id
	@Column(name = "ID")
	private int id;

	public AbstractEvent()
	{
	}
	
	public int getId()
	{
		return id;
	}
	
	public void setId(int id)
	{
		this.id = id;
	}
}
----------------------------

Now, there are two concrete classes, OneConcreteEvent and
AnotherConcreteEvent, each one representing an entity.
----------------------------
package problem;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class OneConcreteEvent extends AbstractEvent
{
	@Column(name = "ATTRIB")
	private int attrib;

	public OneConcreteEvent()
	{
	}

	public int getAttrib()
	{
		return attrib;
	}

	public void setAttrib(int attrib)
	{
		this.attrib = attrib;
	}
}
----------------------------
package problem;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class AnotherConcreteEvent extends AbstractEvent
{
	@Column(name = "ATTRIB", length = 64)
	private String attrib;

	public AnotherConcreteEvent()
	{
	}

	public String getAttrib()
	{
		return attrib;
	}

	public void setAttrib(String attrib)
	{
		this.attrib = attrib;
	}
}
----------------------------

I have defined the test as:
"
package problem;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class EventsTest
{
	private static final Logger logger = LoggerFactory
			.getLogger(EventsTest.class);

	@Autowired
	private EventsDAO eventsDAO;

	@BeforeClass
	public static void beforeClass()
	{
	}

	@Test
	public void test00()
	{
		logger.debug("test" + ": entering");

		{
			OneConcreteEvent event = new OneConcreteEvent();
			event.setId(1);
			event.setAttrib(1);
			eventsDAO.saveEvent(event);
		}

		{
			AnotherConcreteEvent event = new AnotherConcreteEvent();
			event.setId(2);
			event.setAttrib("two");
			eventsDAO.saveEvent(event);
		}

		logger.debug("test" + ": leaving");
	}
}
"

I am instructing the provider to create the necessary tables:
"
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
	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_2_0.xsd";>

	<persistence-unit name="MyPersistenceUnit"
		transaction-type="RESOURCE_LOCAL">

		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

		<class>problem.AbstractEvent</class>
		<class>problem.OneConcreteEvent</class>
		<class>problem.AnotherConcreteEvent</class>

		<properties>

			<property name="eclipselink.logging.level" value="FINE" />
			<property name="eclipselink.target-database" value="HSQL" />
			<property name="eclipselink.ddl-generation" value="create-tables" />
			<property name="javax.persistence.jdbc.url"
value="jdbc:hsqldb:mem:MyDatabase" />
			<property name="javax.persistence.jdbc.driver"
value="org.hsqldb.jdbcDriver" />

		</properties>

	</persistence-unit>

</persistence>"

Since the two classes map fields to columns with same name, the provider
seems to ignore they have different types, and choose one to determine the
type to define the column:
"
[EL Fine]: 2010-11-13
10:50:50.843--ServerSession(8814537)--Connection(14365489)--Thread(Thread[main,5,main])--CREATE
TABLE ABSTRACTEVENT (ID INTEGER NOT NULL, EVENT_TYPE VARCHAR(31), ATTRIB
INTEGER, PRIMARY KEY (ID))
"

Later, when persisting an entity, an INSERT could be attempted on an "odd"
column data type, which results in the exception:
"
org.springframework.transaction.TransactionSystemException: Could not commit
JPA transaction; nested exception is javax.persistence.RollbackException:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: data exception: invalid
character value for cast
Error Code: -3438
Call: INSERT INTO ABSTRACTEVENT (ID, ATTRIB, EVENT_TYPE) VALUES (?, ?, ?)
	bind => [2, two, AnotherConcreteEvent]
Query: InsertObjectQuery(problem.AnotherConcreteEvent@1f7cdc7)
	at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:476)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
	at
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
	at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
	at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
	at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy13.saveEvent(Unknown Source)
	at problem.EventsTest.test00(EventsTest.java:43)
	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
	at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.persistence.RollbackException: Exception [EclipseLink-4002]
(Eclipse Persistence Services - 2.1.1.v20100817-r8050):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: data exception: invalid
character value for cast
Error Code: -3438
Call: INSERT INTO ABSTRACTEVENT (ID, ATTRIB, EVENT_TYPE) VALUES (?, ?, ?)
	bind => [2, two, AnotherConcreteEvent]
Query: InsertObjectQuery(problem.AnotherConcreteEvent@1f7cdc7)
	at
org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
	at
org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
	at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:467)
	... 39 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: data exception: invalid
character value for cast
Error Code: -3438
Call: INSERT INTO ABSTRACTEVENT (ID, ATTRIB, EVENT_TYPE) VALUES (?, ?, ?)
	bind => [2, two, AnotherConcreteEvent]
Query: InsertObjectQuery(problem.AnotherConcreteEvent@1f7cdc7)
	at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:683)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:526)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:980)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:206)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:192)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:341)
	at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:162)
	at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:177)
	at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:465)
	at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
	at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
	at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
	at
org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
	at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:736)
	at
org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:643)
	at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
	at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2909)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1291)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1273)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1233)
	at
org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:224)
	at
org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:123)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3348)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1422)
	at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:546)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1527)
	at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:200)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1148)
	at
org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
	... 41 more
Caused by: java.sql.SQLDataException: data exception: invalid character
value for cast
	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
	at org.hsqldb.jdbc.Util.throwError(Unknown Source)
	at org.hsqldb.jdbc.JDBCPreparedStatement.setParameter(Unknown Source)
	at org.hsqldb.jdbc.JDBCPreparedStatement.setString(Unknown Source)
	at
org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall(DatabasePlatform.java:2035)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:671)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:576)
	... 70 more
Caused by: org.hsqldb.HsqlException: data exception: invalid character value
for cast
	at org.hsqldb.error.Error.error(Unknown Source)
	at org.hsqldb.error.Error.error(Unknown Source)
	at org.hsqldb.Scanner.convertToNumber(Unknown Source)
	at org.hsqldb.types.NumberType.convertToType(Unknown Source)
	... 75 more

"

I would appreciate some help.
Thanks.



tware wrote:
> 
> I still don't see the attachement.  It is probably best to do this in
> bugzilla:
> 
> https://bugs.eclipse.org/bugs/
> 
> File a bug for the project: RT (RuntimeProject) and EclipseLink.  You can
> add 
> attachments to your bug.
> 
> -Tom
> 
> Rui Jesus wrote:
>> I suppose you prefer a single file including all annexes! Here you are!
>> 
>> Thanks.
>> 
>> 
>> tware wrote:
>>> I don't see the attachements, but please file a bug including your
>>> problem 
>>> description and attachments.
>>>
>>> Rui Jesus wrote:
>>>> I forgot the attachments...
>>>>
>>>>
>>>>
>>>> Rui Jesus wrote:
>>>>> JPA provider seems to be unable to detect a potential problem when
>>>>> mapping
>>>>> fields to columns.
>>>>> Having an hierarchy of entities using a single-table strategy, and two
>>>>> entities having fields with same name but different types, results
>>>>> that
>>>>> in
>>>>> a future persist action, a "java.sql.SQLDataException: data exception:
>>>>> invalid character value for cast" is thrown. This is because no two
>>>>> columns exist for the two different fields.
>>>>> I am using version "eclipselink-2.1.1.v20100817-r8050",
>>>>> Springframework-3.0.4, and JUnit-4.8.2.
>>>>> This problem one can reproduce!
>>>>> As annexes, I provide several files including java test files,
>>>>> captured
>>>>> console output, etc.
>>>>>
>>>>>
>>>> http://old.nabble.com/file/p30194812/AbstractEvent.java
>>>> AbstractEvent.java 
>>>> http://old.nabble.com/file/p30194812/AnotherConcreteEvent.java
>>>> AnotherConcreteEvent.java 
>>>> http://old.nabble.com/file/p30194812/console-output.txt
>>>> console-output.txt 
>>>> http://old.nabble.com/file/p30194812/EventsDAO.java EventsDAO.java 
>>>> http://old.nabble.com/file/p30194812/EventsDAOImpl.java
>>>> EventsDAOImpl.java 
>>>> http://old.nabble.com/file/p30194812/EventsTest.java EventsTest.java 
>>>> http://old.nabble.com/file/p30194812/OneConcreteEvent.java
>>>> OneConcreteEvent.java 
>>>> http://old.nabble.com/file/p30194812/persistence.xml
>>>> persistence.xml 
>>>> http://old.nabble.com/file/p30194812/EventsTest-context.xml
>>>> EventsTest-context.xml 
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>
>>>
>> http://old.nabble.com/file/p30199980/EclipselinkProblem.zip
>> EclipselinkProblem.zip 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Undetected-problem-mapping-fields-to-columns-tp30194756p30206152.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top