Java Code Examples for org.hibernate.metadata.ClassMetadata#getIdentifier()
The following examples show how to use
org.hibernate.metadata.ClassMetadata#getIdentifier() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: uyuni File: HibernateFactory.java License: GNU General Public License v2.0 | 6 votes |
/** * Util to reload an object using Hibernate * @param obj to be reloaded * @return Object found if not, null * @throws HibernateException if something bad happens. */ public static Object reload(Object obj) throws HibernateException { // assertNotNull(obj); ClassMetadata cmd = connectionManager.getMetadata(obj); Serializable id = cmd.getIdentifier(obj, (SessionImplementor) getSession()); Session session = getSession(); session.flush(); session.evict(obj); /* * In hibernate 3, the following doesn't work: * session.load(obj.getClass(), id); * load returns the proxy class instead of the persisted class, ie, * Filter$$EnhancerByCGLIB$$9bcc734d_2 instead of Filter. * session.get is set to not return the proxy class, so that is what we'll use. */ // assertNotSame(obj, result); return session.get(obj.getClass(), id); }
Example 2
Source Project: spacewalk File: HibernateFactory.java License: GNU General Public License v2.0 | 6 votes |
/** * Util to reload an object using Hibernate * @param obj to be reloaded * @return Object found if not, null * @throws HibernateException if something bad happens. */ public static Object reload(Object obj) throws HibernateException { // assertNotNull(obj); ClassMetadata cmd = connectionManager.getMetadata(obj); Serializable id = cmd.getIdentifier(obj, EntityMode.POJO); Session session = getSession(); session.flush(); session.evict(obj); /* * In hibernate 3, the following doesn't work: * session.load(obj.getClass(), id); * load returns the proxy class instead of the persisted class, ie, * Filter$$EnhancerByCGLIB$$9bcc734d_2 instead of Filter. * session.get is set to not return the proxy class, so that is what we'll use. */ // assertNotSame(obj, result); return session.get(obj.getClass(), id); }
Example 3
Source Project: jadira File: JpaBaseRepository.java License: Apache License 2.0 | 5 votes |
/** * Determines the ID for the entity * * @param entity The entity to retrieve the ID for * @return The ID */ @SuppressWarnings("deprecation") // No good alternative in the Hibernate API yet protected ID extractId(T entity) { final Class<?> entityClass = TypeHelper.getTypeArguments(JpaBaseRepository.class, this.getClass()).get(0); final SessionFactory sf = (SessionFactory)(getEntityManager().getEntityManagerFactory()); final ClassMetadata cmd = sf.getClassMetadata(entityClass); final SessionImplementor si = (SessionImplementor)(getEntityManager().getDelegate()); @SuppressWarnings("unchecked") final ID result = (ID) cmd.getIdentifier(entity, si); return result; }