Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Not able to get the inserted Entity after Query.getSingleResult(INSERT INTO..... VALUES......) (Not able to get the inserted Entity after Query.getSingleResult(INSERT INTO..... VALUES......) )
Not able to get the inserted Entity after Query.getSingleResult(INSERT INTO..... VALUES......) [message #1067205] Sun, 07 July 2013 15:04 Go to next message
Amrit Debasis is currently offline Amrit DebasisFriend
Messages: 3
Registered: July 2013
Junior Member
Basically My requirement is to insert record into Oracle DB table, in which the PK column has to be filled by a SEQ.NEXTVAL

I want to insert record by, Query query = entitymanager.createnativequery(INSERT stmt ).
To do the insertion, m using query.getSingleResult() to get the inserted record along with the PK (has been inserted by SEQ.NEXTVAL during insertion);

During the execution of query.getSingleResult() stmt, I can see the new record in DB,
But, in my application it gives me invalid sql stmt exception.

Please suggest me, whether m in the right track else let me know how can I get it resolved ?

Thanks in Advance. Smile


Amrit.
Re: Not able to get the inserted Entity after Query.getSingleResult(INSERT INTO..... VALUES......) [message #1067382 is a reply to message #1067205] Mon, 08 July 2013 13:21 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
getSingleResult is for selecting SQL, not update statements, so what statements are you using? Standard JPA usage has users create an Entity and call em.persist to have JPA perform the insert and get the ID value for you, is there a reason why you need to use SQL directly?

See http://wiki.eclipse.org/Introduction_to_EclipseLink_JPA_(ELUG)#Configuring_Sequence_Generation and http://wiki.eclipse.org/EclipseLink/Examples/JPA/PrimaryKey for info on having the Entity use sequencing.

Best Regards,
Chris
Re: Not able to get the inserted Entity after Query.getSingleResult(INSERT INTO..... VALUES......) [message #1067424 is a reply to message #1067382] Mon, 08 July 2013 15:00 Go to previous message
Amrit Debasis is currently offline Amrit DebasisFriend
Messages: 3
Registered: July 2013
Junior Member
First of all many Thanks for your reply, Chris.

To answering your question, why I m using sql directly,

I have to generate my PK value (which is generated by SEQ_REF_ID.NEXTVAL ) in such format like this below,
AD0000000000001
AD0000000000002
AD0000000000003
.
.
.
AD0000000000012
with the help of TO_CHAR() function.
in order to use this method, i prefer to use sql directly.

Many Thanks again.


Amrit.
Previous Topic:Customizing schema generation
Next Topic:Strange behaviour if weaving is enabled
Goto Forum:
  


Current Time: Fri Mar 29 09:27:30 GMT 2024

Powered by FUDForum. Page generated in 0.02873 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top