cancel
Showing results for 
Search instead for 
Did you mean: 

method persist() don't persist the data.

Former Member
0 Kudos

Hello Experts

I have a problem whem i persist a entity.

Often the instance of entity don't persist when i call method persist().

I don't know what happen. The method don't cause any error, but don't have any registry in the database after passing the persist() method.

Att.

Marcos

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Active Participant
0 Kudos

Hi Marcos,

persist() only registers an entity to be inserted upon flush. If you don't commit, no flush occurs and your changes are lost.

Sure you are commiting your transaction?

-Adrian

Former Member
0 Kudos

Hi Adrian

Thanks for your quickly reply.

i don't use the method flush. But in other entity, i do the same process and the data is commit in database. i've compared these two entity, and they are equals. the only diference is the quantity of attributes in both.

I try to use the method flush in both entity. In the first is OK, the data is commited. In the second cause one error.

When i don't use the method flush, the same happend, the first commit, the second don't commit, but don't cause error.

Waiting for anwser.

Thanks.

Marcos.

adrian_goerler
Active Participant
0 Kudos

Hi,

> I try to use the method flush in both entity. In the first is OK, the data is commited. In the second cause one error.

Which error is it causing? Are you getting some stack trace?

-Adrian

Former Member
0 Kudos

Hi

this is the error that i get:

javax.persistence.PersistenceException: SQL exception while inserting entity: Class >>br.com.teclogica.demo.mobile.entity.LogClientIncidentes<<. Id values: (idLog=1).

and the error message:

SQL exception while inserting entity: Class >>br.com.teclogica.demo.mobile.entity.LogClientIncidentes<<. Id values: (idLog=1).

The table in database is empty, and the sequence isn't start.

Thanks.

Marcos

adrian_goerler
Active Participant
0 Kudos

Hi Marcos,

the stack trace of this exception should show the causing SQLException. Could you please provide us with the complete stack trace?

-Adrian

Former Member
0 Kudos

Hi Adrian

These errors i get in a Location log. I don't know where i could get the entire stack trace of the exception.

thanks.

Marcos

Former Member
0 Kudos

Hi Adrian,

I found in archive "database_00.0.log" the SQL error cause this problem.

Now i fixed the error and the data is commited in the database.

But it is a realy big problem. When the database throw some error, the method persist don't throw any error. Its just do nothing, the process to persist like normal with no error to the application.

I believe this behavoir isn't normal.

Have you seen anything like this?

Thanks.

Marcos.

adrian_goerler
Active Participant
0 Kudos

Hi Marcos,

persist() just registers an entity to be inserted upcon flush/commit. The actual INSERT is defered to the future. Therefore, you can't observe a failure due to some SQL Exception during the execution of the persist method. You'll get it only at flush/commit.

-Adrian

Former Member
0 Kudos

Hi Adrian

Now i understood...

When i use persist without flush, the entity will be persist in database, but don't in the exactly moment when this method is called. If ocurr some error, this error cannot be throw, because the process of persist will ocurr in the future. When i called flush method, the process of persist will be complete in the moment when i called it, and if ocurr some error, this error will be threw.

Is this right?

Thanks for your help Adrian.

Marcos

adrian_goerler
Active Participant
0 Kudos

Yes. This is how it works.

-Adrian

Answers (0)