顯示具有 hibernate 標籤的文章。 顯示所有文章
顯示具有 hibernate 標籤的文章。 顯示所有文章

2011年11月30日 星期三

使用Hibernate做Batch Delete

讓HQL派上用場吧!這種時候它滿好用的。
result = session
           .createQuery("DELETE FROM Scope2camera WHERE scope_id = :scope_id")
           .setLong("scope_id", scopeId).executeUpdate();

2011年8月23日 星期二

使用Maven遇到"java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file"錯誤

筆者在使用JAX-RS (Jersey)及Java EE 6 API時,執行"mvn test",會出現類似以下的錯誤
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/MediaType
...
原因是Java EE 6只是一個Interface,必須要等到hibernate jars讀取進來,實作這些JPA interface,因此要調整Java-ee-api在pom.xml裡面的位置,才不會出現這個錯誤。


	com.sun.jersey
	jersey-server
	1.0.1




	org.hibernate
	hibernate-core
	3.6.6.Final



	org.hibernate
	hibernate-entitymanager
	3.6.6.Final



	org.hibernate
	hibernate-validator
	4.0.2.GA




	javax
	javaee-api
	6.0
	provided

Reference: stackoverflow

2011年8月11日 星期四

org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity()

Simply check "Use Java 5 Syntax" as depicted in the attached Screenshot and Hibernate Tools generate the correct generic types for collections.

Reference: stackoverflow, mkyong

遇到"javax.persistence.OneToMany.orphanRemoval()Z"錯誤

# 因為使用到了persistence-api-1.0.jar,要改用2.0 API
# 修改pom.xml

  org.hibernate
  hibernate-entitymanager
  3.6.6.Final
 
Reference: stackoverflow

2011年6月8日 星期三

Solved: Failed to load class org.slf4j.impl.StaticLogger

當使用 Hibernate 遇到" Failed to load class org.slf4j.impl.StaticLogger "這個問題時,
只需要把 slf4j-nop-1.6.1.jar 匯入即可。

Reference:陽光e站