简体   繁体   中英

how to get generated primary key after persisting record in Camel

I am trying to get the primary key which is autogenerated after inserting data into the database using Camel. I saw, there was a JIRA issue( https://issues.apache.org/jira/browse/CAMEL-7313 ) and it was resolved.

                     from("file:data/source?noop=true")
                        .to("validator:books.xsd")
                        .split()
                        .tokenizeXML("book")
                        .unmarshal(jaxb)
                        .to("jpa:com.labs.Book")
                        .process(new Processor() {
                            public void process(Exchange exchange)
                                    throws Exception {
                                //here i want to get that primary key
                            }
                        });

Can someone point me to an example for this ....

Yeah after some googling and suggestions from the experts above. I got the answer for my question

from("file:data/source?noop=true")
                        .to("validator:books.xsd")
                        .split()
                        .tokenizeXML("book")
                        .unmarshal(jaxb)
                        .to("jpa:com.labs.Book")
                        .process(new Processor() {
                            public void process(Exchange exchange)
                                    throws Exception {
                                //here it is
                                int Id = exchange.getIn().getBody(Book.class).getId();
                            }
                    });

Thank you everyone.

The primary key gets set on the entity class, so check that class. You need to configure your JPA entity with the JPA annotations, where you define which field is the primary key.

Just search the web or this site for jpa primary key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM