persist « ID « JPA Q&A





1. Hibernate/persistence without @Id    stackoverflow.com

I have a database view thar yields a result set that has no true primary key. I want to use Hibernate/Persistence to map this result set onto Java objects. Of course, ...

2. Changing the type of an entity preserving its ID    stackoverflow.com

I am using hibernate as a persistence layer. There are 2 entities that live in the same table extending one superclass with single table inheritance strategy.

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class A ...

3. Why JPA persist() does not generated auto-increment primary ID?    stackoverflow.com

I'm using JPA toplink-essential and SQL Server 2008 My goal is to get auto-increment primary key value of the data that is going to be inserted into the table. I know in ...

4. jpa persist increment id twice    coderanch.com

Hi to forum. I have a problem with JPA and persist. I'm working with oracle database and I have created a Trigger, which increments id by 1. This is the trigger: CREATE OR REPLACE TRIGGER MDITADMIN."BI_MITD_ENTIDADES" before insert on "MITD_ENTIDADES" for each row begin select "MITD_SEQ_ENTIDADES".nextval into :NEW.ID_ENTIDADES from dual; end; My problem is, when I tried to insert an object, ...

5. generating an id before the object is persisted    forum.hibernate.org

"native" isn't an actual identifier generator, it's a placeholder that turns into "sequence", "identity", or "hilo", depending on the database Dialect. Those three generators all behave differently. The "identity" generator uses identity columns for those databases that support it, and I don't think you can really know what the identifier will be until after you insert the record (I think it's ...

6. Business Key (Natural-id) and multiple persistent classes    forum.hibernate.org

Hi all, I've a situation where my business key is a combination of properties of two persistent entities. I am not sure how to use the "natural-id" element to group them. Following should be my business key csaType + csaStartDate + csaEndDate + serialNumber (from Equipment.hbm.xml) I appreciate your help. Thank you in advance! Hibernate version: 3.x Mapping documents: Csa.hbm.xml

7. I need to get the ID form a newly persisted object    forum.hibernate.org

protected void entityIsTransient(MergeEvent event, Map copyCache) { super.entityIsTransient(event, copyCache); SessionImplementor session = event.getSession(); EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity()); // Extract id from merged copy (which ...

8. I need to get the ID form a newly persisted object    forum.hibernate.org

protected void entityIsTransient(MergeEvent event, Map copyCache) { super.entityIsTransient(event, copyCache); SessionImplementor session = event.getSession(); EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity()); // Extract id from merged copy (which ...

9. Hibernate returning zero for the ID of a persistent object    forum.hibernate.org

Author Message archie172 Post subject: Hibernate returning zero for the ID of a persistent object Posted: Wed Jan 17, 2007 1:31 pm Newbie Joined: Tue Nov 16, 2004 1:10 pm Posts: 5 I've isolated what appears to me to be a fairly straightforward bug. Instead of repeating the description and file attachments here, I went ahead and filed a ...





10. Read only Objects, Dont need to persist id    forum.hibernate.org

Hibernate version: 3.2 I have lot of data in the database which is updated thru some different process(Not Hibernate). In UI(where I'm using Hibernate), I just need to read and show this data. I dont need to persist this data from UI. All I need is to display it in UI. This data is stored in legacy database with legacy schema. ...

11. Change an id's value for a persistent object    forum.hibernate.org

12. Change an id's value for a persistent object    forum.hibernate.org

13. can't persist new entity - id of the wrong type    forum.hibernate.org

When trying to insert an entity into the database as in Code: MyDbObj obj = new MyDbObj(); entityManager.persist(obj); I get the following exception: Expected: class java.lang.Integer, got class org.hibernate.action.DelayedPostInsert Identifier This only happens if doing the add is the first thing I do on a page. If I edit a db object or delete one before adding, everything seems to work ...

14. How to get the id from persisted objects when using JPA    forum.hibernate.org

This may seem a silly question but: If I have an object similar to below, and use JPA/hib to create the id. @Entity public class Item { @Id @GeneratedValue private Long id; private String name; ... getters/setters ... } then do: Item item1 = new Item(); item1.setName("Test Name"); em.persist(item1); Item item2 = new Item(); item2.setName("Test Name"); em.persist(item2); Given that it's created ...

15. Obtaining generated entity ID from JPA persist()    forum.hibernate.org

I hope this is not a FAQ and that it's OK to ask JPA questions on this forum. I'm using JBoss with JPA and Hibernate..... With Hibernate, I am able to retrieve the generated ID of a newly saved object via: Serializable id = Session.save(newObject); However, switching to JPA this is not an option since persist() does not return the new ...