hibernate 3.6中的一个小bug,javax.persistence.OneToMany.orphanRemoval()Z

[size=medium;][size=x-small]    虽然说hibernate现在支持了annotation注解方式进行映射,但是仍然有的诸多的不完善与不稳定。
    特别是最近在开发项目的过程中,居然还出现莫名奇妙的错误,一开整的人都差点崩溃了!最后,测试出来,居然是annotation的支持出问题。
    而问题更是让人崩溃呢!在java项目中使用annotation是没有任何问题的,可是一改用web项目时,就一定报错。这时只能改用xml来配置了!
    其中之一的bug:多对一(@ManyToOne)
    例子如下:
[/size] [/size]

java代码
User类代码

package hibernater.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Table(name="t_user")
@Entity
public class User {

private int id;
private String name;

@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


Group类代码:

package hibernater.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Table(name="t_group")
@Entity
public class Group {

private int id;
private String name;
private Set groupSet=new HashSet();



@OneToMany
@JoinColumn(name="groupId")
public Set getGroupSet() {
return groupSet;
}
public void setGroupSet(Set groupSet) {
this.groupSet = groupSet;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

}

Test测试类:

package com.test;

import java.util.Date;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class Test {

private static SessionFactory sf;

@Before
public static void before() {
sf = new AnnotationConfiguration().configure().buildSessionFactory();
}

@Test
public void testSchemaExport() {

new SchemaExport(new AnnotationConfiguration().configure()).create(
true, true);

}

@After
public static void after() {
sf.close();
}

}


其他如hibernate.cfg.xml配置都是正确的,如果这是在java项目中执行时没有问题的,
可是如果放在web项目中,就一定会报如下错误:

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

测试了很多的方法,应该可以证明这是hibernate3.6中annotation的一个bug


猜你喜欢

转载自876473249-qq-com.iteye.com/blog/1043950