[MDEV-14878] JPA ignores field in class - not present in db table Created: 2018-01-06  Updated: 2018-01-08  Resolved: 2018-01-08

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0.33-galera
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Trond Arild Lode Tobiassen Heidelberg Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Jdk 8 151
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.1.7</version>
</dependency>
win 7
glassfish 4.1(javaee 7)



 Description   

Exception when trying to insert into empty table.

PLEASE SEE COMMENT IN UPPERCASE BELOW.

jan 06, 2018 4:14:12 PM org.eclipse.persistence.session.file:/C:/Users/trond/AppData/Local/Temp/ejb-app2357173617210013789/d__2__classes_jar/_REGDB
WARNING: 
Local Exception Stack: 
Exception [EclipseLink-6023] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException
Exception Description: The list of fields to insert into the table [DatabaseTable(CALL_SESSION_TABLE)] is empty.  You must define at least one mapping for this table.
Query: InsertObjectQuery(null)
	at org.eclipse.persistence.exceptions.QueryException.objectToInsertIsEmpty(QueryException.java:962)
	at org.eclipse.persistence.internal.expressions.SQLInsertStatement.buildCallWithoutReturning(SQLInsertStatement.java:59)
	at org.eclipse.persistence.internal.expressions.SQLModifyStatement.buildCall(SQLModifyStatement.java:61)
	at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:813)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:390)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.prepareInsertObject(StatementQueryMechanism.java:304)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareInsertObject(ExpressionQueryMechanism.java:1687)
	at org.eclipse.persistence.queries.InsertObjectQuery.prepare(InsertObjectQuery.java:111)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:613)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:218)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:193)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:138)
	at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4207)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1587)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:452)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:863)
	at com.sun.enterprise.container.common.impl.EntityManagerWrapper.flush(EntityManagerWrapper.java:437)
	at no.tobiassenit.sip.registrar.util.EntityMethods.mergeContactSession(EntityMethods.java:68)
	at no.tobiassenit.sip.registrar.dialog.MessageToTransactionInTransactionSequence.add(MessageToTransactionInTransactionSequence.java:90)
	at no.tobiassenit.sip.registrar.client.HandleRegisterFromCsipSimple.run(HandleRegisterFromCsipSimple.java:147)
	at no.tobiassenit.sip.registrar.mdb.RegistrarMDB.onMessage(RegistrarMDB.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
	at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
	at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
	at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
	at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
	at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
	at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
	at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
	at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
	at org.glassfish.ejb.mdb.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1219)
	at org.glassfish.ejb.mdb.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:81)
	at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:171)
	at com.sun.proxy.$Proxy299.onMessage(Unknown Source)
	at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:283)
	at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:107)
	at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
	at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

Class def:

@Entity(name = "CALL_SESSION_TABLE")
public final class CallSession<T extends TransactionSequence<T>> implements IIsValid, Serializable {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1430258908526999629L;
 
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Long id;
 
	public Long getId() {
		return id;
	}
 
	private void setId(Long id) {
		this.id = id;
	}
 
	public CallSession() {
	}
 
	protected CallSession(CallSession<T> inp) {
		if (inp != null) {
			this.id = inp.id;
			if (inp.transactionSequenceHolders != null) {
				this.transactionSequenceHolders = Lists.newLinkedList();
				for (TransactionSequenceHolder<T> holder : inp.transactionSequenceHolders) {
					this.transactionSequenceHolders.add(holder.copy());
				}
			}
		}
	}
 
 
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "CALL_SESSION_ID", unique = false, nullable = false, updatable = false)
	private List<TransactionSequenceHolder<T>> transactionSequenceHolders;

This table should be empty except for id which is present.



 Comments   
Comment by Trond Arild Lode Tobiassen Heidelberg [ 2018-01-06 ]

Also, this works fine under Oracle 12c.

THE HEADING OF THE BUG DESCRIPTION IS MISLEADING. THE TABLE SHOULD HAVE ONLY ONE COLUMN - THE AUTOINCREMENTED ID PRIMARY KEY COLUMN. THE PROBLEM IS THAT THE INSERT WITH NO COLUMNS FAILS. ORACLE ALLOWS THIS. IS THERE A SETTING IN MY.INI FOR THIS?

Comment by Elena Stepanova [ 2018-01-07 ]

What is the final INSERT that gets generated and received by the server?
If you are receiving some error from the server, please quote it, along with the error code.

Comment by Trond Arild Lode Tobiassen Heidelberg [ 2018-01-07 ]

Unfortunately eclipselink does not report the actual INSERT - only the error code 6023 (not mariadb I guess?) All I get is in the exception log provided.

Comment by Daniel Black [ 2018-01-07 ]

As you alluded to in your first comment the available features depends on the database base implementation.

This looks like a few things on stack overflow.
like https://stackoverflow.com/questions/17272819/insert-row-to-table-with-the-only-identifier-column-with-eclipselink
and https://stackoverflow.com/questions/15538959/you-must-define-at-least-one-mapping-for-this-table

If you enable the general query log on the server you can see the INSERT statement (if it actually gets to the server. Its quite possible it isn't getting that far.

A SHOW CREATE TABLE CALL_SESSION_TABLE will be useful too.

In MariaDB/MySQL you can insert just NULL Into an auto_increment column and it will get a value.

CREATE TABLE b (i  bigint unsigned auto_increment primary key);
 
insert into b values ( NULL );
show create table b;
 
CREATE TABLE `b` ( `i` bigint(20) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`i`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
 
select * from b;
i: 1

https://stackoverflow.com/questions/17229464/jpa-queryexception-the-list-of-fields-to-insert-into-the-table-is-empty
indicates that GenerationType.TABLE is required.

Comment by Trond Arild Lode Tobiassen Heidelberg [ 2018-01-07 ]

Found the problem. The

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)

annotations were adapted to Oracle an did not work on MariaDB

I removed (strategy=GenerationType.SEQUENCE) and autogenrate of id works and the above issue is gone.

Comment by Trond Arild Lode Tobiassen Heidelberg [ 2018-01-07 ]

Just like Daniel proposed.

Comment by Elena Stepanova [ 2018-01-07 ]

diego dupin, you said you wanted this one, do you still?

Comment by Diego Dupin [ 2018-01-07 ]

elenst no need, but i've create CONJ-569 to check that with 10.3

Generated at Thu Feb 08 08:16:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.