如何解决 Hibernate + Weblogic (JNDI) 应用程序中的以下 ServiceException?

How to solve following ServiceException in Hibernate + Weblogic (JNDI) application?

我在我的 Weblogic Server 12c 上创建了一个 JNDI。我正在尝试使用数据源连接到服务器上的 Oracle 数据库,并使用休眠在其中创建 table。但我不断收到相同的异常 org.hibernate.service.spi.ServiceException:无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] Part 1 Part 2。这个异常发生在我从 index.jsp 提交 id 和 name 之后 请查看我的 java 代码并提出任何更改建议:

版本: Java 8 网络逻辑 12c 休眠 5 甲骨文 11g

Project Structure

Jar Files

Hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.datasource">java:comp/env/jdbc/Abc</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <mapping class="packone.Bean"/>
    </session-factory>
</hibernate-configuration>

Context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="jdbc/Abc"
        auth="container"
        type="javax.sql.DataSource"
        driverClassName="oracle.jdbc.OracleDriver"
        url="jdbc:oracle:thin:@//RAPC01-1702-26:1521/P1130PL2"
        username="root"
        password="root"

        maxActive="100"
        maxIdle="20"
        minIdle="5"
        maxWait="10000">
    </Resource>
</Context>

HibernateUtil.java:

private static StandardServiceRegistry standardServiceRegistry;
private static SessionFactory sessionFactory;

public Session getSession(List<String> list) {
    list.add("START: getsession");
    if(sessionFactory == null) {
        try {
            standardServiceRegistry = new StandardServiceRegistryBuilder().configure().build();
            MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
            Metadata metadata = metadataSources.getMetadataBuilder().build();
            sessionFactory = metadata.getSessionFactoryBuilder().build();
        } catch(Exception e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            list.add(sw.toString());
        }
    }
    list.add("END: getsession");
    return sessionFactory.openSession();
}

web.xml: 仅包含欢迎文件列表 index.jsp

index.jsp:

<%
List<String> list = (List<String>)request.getAttribute("lsit");
if(list==null) {

} else {
    for(String str: list) {
        %> <%=str %><br> <%
    }
}
%>
<form action="BeanServlet">
<input type="text" name="id" placeholder="Enter Id...">
<input type="text" name="name"  placeholder="Enter Name...">
<input type="submit">
</form>

Bean.java:

package packone;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Bean {

    @Id
    private int id;
    private String name;

    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;
    }
}

BeanServlet.java:

List<String> list = new ArrayList<>();
        list.add("servlet started");
        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("name");

        list.add("id value: "+id);
        list.add("name value: "+name);

        Bean B = new Bean();
        B.setId(id);
        B.setName(name);

        new BeanDAO().createBean(B, list);

        list.add("servlet before RD");

        request.setAttribute("lsit", list);
        RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
        rd.forward(request, response);

BeanDAO.java:

package packone;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

import org.hibernate.Session;

public class BeanDAO {

    public void createBean(Bean B, List<String> list) {
        Session session = null;
        try {
            list.add("START: DAO");
        session = new HibernateUtil().getSession(list); 
        list.add("Arriva Session");
        session.beginTransaction();
        session.save(B);
        session.getTransaction().commit();

        list.add("END: DAO");
        } catch(Exception e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            list.add(sw.toString());
        } finally {
            if(session != null) {
                session.flush();
                session.close();
            }
        }
    }

}

如果您需要更多详细信息或问题格式是否需要改进,请告诉我。顺便说一句,不是 Weblogic 专家。谢谢。

我觉得一切都很好。

尝试使用 ojdbc6.jar 而不是 ojdbc14.jar。由于您的 Oracle 是版本 11,而 java 是 8。ojdbc14.jar 现在已经很旧了。

如果有效请告诉我。