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

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

}

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

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

测试了很多的方法,应该可以证明这是hibernate3.6中annotation的一个bug[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值