我正在使用hibernate 3.2.5和postgres9创建一个小程序。 我有一个例外,
” 严重:无法找到数据源:STUD javax.naming.NoInitialContextException:需要在环境或系统属性中指定类名,或在applet参数中或在应用程序资源文件中指定类名:java.naming.factory.initial “
学生可以学习很多科目。
请按以下方式查找我的代码,
Student.java
@Entity
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="Student_ID")
private Long id;
@Column(name="Name")
private String name;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="Student_ID")
private Set<Subjects> SubjectsSet;
public Set<Subjects> getSubjectsSet() {
return SubjectsSet;
}
public void setSubjectsSet(Set<Subjects> SubjectsSet) {
this.SubjectsSet = SubjectsSet;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
File Subjects.Java
@Entity
public class Subjects implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name="Subject")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
我的persitence.xml
< persistence-unit name="HibOneToManyPU2" transaction-type="JTA" >
< provider >org.hibernate.ejb.HibernatePersistence</ provider >
< jta-data-source >StudSub </ jta-data-source >
< class > model.Student </ class >
< class > model.Subjects </ class >
< exclude-unlisted-classes > false </ exclude-unlisted-classes >
< properties >
< property name="hibernate.hbm2ddl.auto" value="create-drop" />
</ properties >
</ persistence-unit >
</ persistence >
请让我知道如何解决此问题。