Key / Id Property ermitteln#

Session session = (Session)entityManager.getDelegate();
ClassMetadata metadata = session.getSessionFactory().getClassMetadata(type);
String keyName = metadata.getIdentifierPropertyName();
Class<?> keyType = metadata.getIdentifierType().getReturnedClass();

Spring JPA#

applicationContext.xml:
	<context:component-scan base-package="com.intersult"/>
	<aop:config proxy-target-class="true"/>
	<aop:aspectj-autoproxy/>
	
	<bean id="dataSource" class="${dataSource.class}" destroy-method="close">
		<property name="URL" value="${dataSource.url}"/>
		<property name="user" value="${dataSource.username}"/>
		<property name="password" value="${dataSource.password}"/>
	</bean>
	
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<property name="loadTimeWeaver">
			<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory"/>
	</bean>

	<tx:annotation-driven/>