hibernate无法访问oracle 总是报ORA-12505错误

beetle 发布于 2012/12/17 15:22
阅读 776
收藏 0

我有一个项目原来是用mysql做的,运行没问题。现在需要移植到oracle数据库上。每次用hibernate自动生成表总是报ORA-12505错误。后来自己在oracle上创建了数据表,但是插入数据的时候还是会报ORA-12505错误。我用的hibernate3.6, oracle11g,驱动程序用的是oracle11g自带的ojdbc6.jar,dialect是Oracle10gDialect。网上也查过,通常说的修改listener.ora文件的方法也试过了,还是没用。但是用原始的jdbc连接没问题。hibernate配置文件如下:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<session-factory>

		<!-- Database connection settings -->
		<!-- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="connection.url">jdbc:mysql://localhost:3306/messagecenter</property>
		<property name="connection.username">root</property>
		<property name="connection.password">1234</property> -->
		
		<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
		<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl></property>
		<property name="connection.username">system</property>
		<property name="connection.password">Jdwm820416</property>

		<!-- JDBC connection pool (use the built-in) -->
		<!--  <property name="connection.pool_size">1</property> -->

		<!-- SQL dialect -->
		<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property> -->
		<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

		<!-- Enable Hibernate's automatic session context management -->
		 <property name="current_session_context_class">thread</property> 

		<!-- Disable the second-level cache -->
		<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

		<!-- Echo all executed SQL to stdout -->
		<property name="show_sql">true</property>
		<property name="format_sql">true</property>

		<!-- Drop and re-create the database schema on startup -->
		<!--<property name="hbm2ddl.auto">update</property> 
		<property name="hbm2ddl.auto">create</property>--> 

		
		
		
		<mapping class="com.messagecenter.model.Factory"/>
		<mapping class="com.messagecenter.model.Facunit"/>
		<mapping class="com.messagecenter.model.Item"/>
		<mapping class="com.messagecenter.model.Department"/>
		

	</session-factory>

</hibernate-configuration>
现在项目马上要交工了   甚急!!!请各位帮帮忙

加载中
0
lock_free
lock_free
把pojo和hbm配置拿出来看看吧
0
beetle
beetle

这个项目目前只有四张表。

department:


package com.messagecenter.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;







@Entity
public class Department implements Serializable{
	private int id;
	private String dep_name;
	private String dep_master;
	private int duty_peoples;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getDep_name() {
		return dep_name;
	}
	public void setDep_name(String dep_name) {
		this.dep_name = dep_name;
	}
	public String getDep_master() {
		return dep_master;
	}
	public void setDep_master(String dep_master) {
		this.dep_master = dep_master;
	}
	public int getDuty_peoples() {
		return duty_peoples;
	}
	public void setDuty_peoples(int duty_peoples) {
		this.duty_peoples = duty_peoples;
	}
	
}

factory:

package com.messagecenter.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Factory implements Serializable{
	private int id;
	private String fac_name;
	private String fac_master;
	private String fac_sczg;
	private int fac_scx_number;
	private double fac_myd;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getFac_name() {
		return fac_name;
	}
	public void setFac_name(String fac_name) {
		this.fac_name = fac_name;
	}
	public String getFac_master() {
		return fac_master;
	}
	public void setFac_master(String fac_master) {
		this.fac_master = fac_master;
	}
	public String getFac_sczg() {
		return fac_sczg;
	}
	public void setFac_sczg(String fac_sczg) {
		this.fac_sczg = fac_sczg;
	}
	public int getFac_scx_number() {
		return fac_scx_number;
	}
	public void setFac_scx_number(int fac_scx_number) {
		this.fac_scx_number = fac_scx_number;
	}
	public double getFac_myd() {
		return fac_myd;
	}
	public void setFac_myd(double fac_myd) {
		this.fac_myd = fac_myd;
	}
	
}
facunit:

package com.messagecenter.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Facunit implements Serializable{
	private int id;
	private String facunit_name;
	private Factory factory;
	private String facunit_dj;
	private String facunit_nx_dj;
	private String facunit_dx_dj;
	private String facunit_rx_dj;
	private String facunit_qx_dj;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getFacunit_name() {
		return facunit_name;
	}
	public void setFacunit_name(String facunit_name) {
		this.facunit_name = facunit_name;
	}
	@ManyToOne(cascade = {CascadeType.MERGE})
	@JoinColumn(name = "fac_id")
	public Factory getFactory() {
		return factory;
	}
	public void setFactory(Factory factory) {
		this.factory = factory;
	}
	public String getFacunit_dj() {
		return facunit_dj;
	}
	public void setFacunit_dj(String facunit_dj) {
		this.facunit_dj = facunit_dj;
	}
	public String getFacunit_nx_dj() {
		return facunit_nx_dj;
	}
	public void setFacunit_nx_dj(String facunit_nx_dj) {
		this.facunit_nx_dj = facunit_nx_dj;
	}
	public String getFacunit_dx_dj() {
		return facunit_dx_dj;
	}
	public void setFacunit_dx_dj(String facunit_dx_dj) {
		this.facunit_dx_dj = facunit_dx_dj;
	}
	public String getFacunit_rx_dj() {
		return facunit_rx_dj;
	}
	public void setFacunit_rx_dj(String facunit_rx_dj) {
		this.facunit_rx_dj = facunit_rx_dj;
	}
	public String getFacunit_qx_dj() {
		return facunit_qx_dj;
	}
	public void setFacunit_qx_dj(String facunit_qx_dj) {
		this.facunit_qx_dj = facunit_qx_dj;
	}
	
}
item:

package com.messagecenter.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.IndexColumn;

@Entity
public class Item implements Serializable{
	private int id;
	private Facunit facunit;
	private String item_name;
	private String item_startdate;
	private String item_stopdate;
	private double item_workhour;
	private Set<Department> departments = new HashSet<Department>();
	private String item_note;
	private String item_xmlx;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
	@ManyToOne(cascade = {CascadeType.MERGE})
	@JoinColumn(name = "facunit_id")
	public Facunit getFacunit() {
		return facunit;
	}
	public void setFacunit(Facunit facunit) {
		this.facunit = facunit;
	}
	
	@ManyToMany(cascade = {CascadeType.MERGE},fetch=FetchType.EAGER)
	//@IndexColumn(name="item_department",base=1)
	@JoinTable(name = "item_department", joinColumns = { @JoinColumn(name = "itemid") },//本实体对应的中间表字段
			inverseJoinColumns={@JoinColumn(name="departmentid")})//与本实体联接的对应实体的中间表字段
	public Set<Department> getDepartments() {
		return departments;
	}
	public void setDepartments(Set<Department> departments) {
		this.departments = departments;
	}
	public String getItem_name() {
		return item_name;
	}
	public void setItem_name(String item_name) {
		this.item_name = item_name;
	}
	public String getItem_startdate() {
		return item_startdate;
	}
	public void setItem_startdate(String item_startdate) {
		this.item_startdate = item_startdate;
	}
	public String getItem_stopdate() {
		return item_stopdate;
	}
	public void setItem_stopdate(String item_stopdate) {
		this.item_stopdate = item_stopdate;
	}
	public double getItem_workhour() {
		return item_workhour;
	}
	public void setItem_workhour(double item_workhour) {
		this.item_workhour = item_workhour;
	}
	public String getItem_note() {
		return item_note;
	}
	public void setItem_note(String item_note) {
		this.item_note = item_note;
	}
	public String getItem_xmlx() {
		return item_xmlx;
	}
	public void setItem_xmlx(String item_xmlx) {
		this.item_xmlx = item_xmlx;
	}
	
	
}


0
lock_free
lock_free

oracle 自增 要sequence。我是这么配的 。

<id name="userId" >
<column name="USER_ID"  />
<generator class="sequence">
<param name="sequence">USERS_USER_ID_SEQ</param>
</generator>
</id>

0
Wentasy
Wentasy
javax.persistence下的是EJB的东西吧。
铂金小虫
铂金小虫
回复 @Burning_BL : 而且只是注释部分,都没有用JPA的实现。
铂金小虫
铂金小虫
@Wentasy JPA只是EJB的一部分,这里这种只是JPA。
Wentasy
Wentasy
回复 @Burning_BL : EJB的Entity Bean不就是用的JPA?
铂金小虫
铂金小虫
这个只是用了JPA注释。
0
beetle
beetle
我这里是用JPA注解方式配置hbm的  貌似跟自增没关系吧  现在主要问题是老是报 ORA-12505错误。
返回顶部
顶部