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 11:04 Go to next message
Amrit Debasis is currently offline Amrit Debasis
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 09:21 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
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 11:00 Go to previous message
Amrit Debasis is currently offline Amrit Debasis
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: Sat Apr 19 06:01:43 EDT 2014

Powered by FUDForum. Page generated in 0.10825 seconds