in Education by
My problem is the same as described in [1] or [2]. I need to manually set a by default auto-generated value (why? importing old data). As described in [1] using Hibernate's entity = em.merge(entity) will do the trick. Unfortunately for me it does not. I neither get an error nor any other warning. The entity is just not going to appear in the database. I'm using Spring and Hibernate EntityManager 3.5.3-Final. Any ideas? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Another implementation, way simpler. This one works with both annotation-based or xml-based configuration: it rely on hibernate meta-data to get the id value for the object. Replace SequenceGenerator by IdentityGenerator (or any other generator) depending on your configuration. (The creation of a decorator instead of subclassing, passing the decorated ID generator as a parameter to this generator, is left as an exercise to the reader). public class UseExistingOrGenerateIdGenerator extends SequenceGenerator { @Override public Serializable generate(SessionImplementor session, Object object) throws HibernateException { Serializable id = session.getEntityPersister(null, object) .getClassMetadata().getIdentifier(object, session); return id != null ? id : super.generate(session, object); } } Answer to the exercise (using a decorator pattern, as requested), not really tested: public class UseExistingOrGenerateIdGenerator implements IdentifierGenerator, Configurable { private IdentifierGenerator defaultGenerator; @Override public void configure(Type type, Properties params, Dialect d) throws MappingException; // For example: take a class name and create an instance this.defaultGenerator = buildGeneratorFromParams( params.getProperty("default")); } @Override public Serializable generate(SessionImplementor session, Object object) throws HibernateException { Serializable id = session.getEntityPersister(null, object) .getClassMetadata().getIdentifier(object, session); return id != null ? id : defaultGenerator.generate(session, object); } }

Related questions

0 votes
    What is used to specify db type used in application to hibernate? Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    8. ____ is not essential component of mail merge. a) main document b) data source c) salutation d) merged document Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Bitcoin network would make it impossible to bypass the traditional financial intermediaries. A. True B. False...
asked Nov 30, 2022 in Education by JackTerrance
0 votes
    So, I was trying to upload PHP files into Apache server, and whenever I browse the file I get 403 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    So, I was trying to upload PHP files into Apache server, and whenever I browse the file I get 403 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    For some reason, when I try to install SQL Server 2008 Express, I get an error saying that I need ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    For some reason, when I try to install SQL Server 2008 Express, I get an error saying that I need ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    My goal here is to delete the correspondent data in mysql db table using AJAX. So I've generated a table with several rows and want to a non specific row... PHP Code:...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have a @Stateless-Bean which performs some Database operations in a single method public void doOperation() ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I have a @Stateless-Bean which performs some Database operations in a single method public void doOperation() ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Is there any way to stop a SQL Azure DB so that it doesn't charge anything towards our account? I don't ... cloud services and VM's. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to reshape data from long to wide format (12 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    Here are two data frames : df1 = data.frame(CId = a(1:6), Item = b(rep("TV", 3), rep("Book", 3 ... I do a SQL style select statement Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    2.A feature of Microsoft Word which is used to create multiple copies of letters and e-mails is (a) Mail (b) ... merge (d) data source Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    read the data from employee. text file and sort on age using counting sort,merge sort,quick sort and write ... sortedemponage.txt'. Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
...