Home > Mobile >  hibernate integration with postgres error com.sun.xml.bind.v2.runtime.reflect.opt.Injector <clini
hibernate integration with postgres error com.sun.xml.bind.v2.runtime.reflect.opt.Injector <clini

Time:04-12

I'm making a simple program to connect hibernate with the Postgres server but I'm getting errors in it. I've also downloaded and used the jar files that are used in another StackOverflow question but the issue isn't getting resolved.

App.java

package com.ayush;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class App
{
    public static void main(String[] args) {
        System.out.println("Project started..");
        SessionFactory factory= new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
    
        
        System.out.println(factory);
        
    }
}

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="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/myhiber</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">password</property>
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="show_sql">true</property>
    </session-factory>



</hibernate-configuration>

Ive also included these jar files in my project .

  • javax.activation-1.2.0.jar
  • jaxb-api-2.3.0.jar
  • jaxb-core-2.3.0.jar
  • jaxb-impl-2.3.0.jar

And the tree structure is like this for the project

tree structure in my eclipse compiler with the error message

CodePudding user response:

The hibernate config always needs to be located inside the resources folder.

  1. Create a folder named "resources"
  2. Right-click your project < Properties < Java Build Path < Source < Add folder
  3. Add the resource folder as Source

Now move the hibernate config file into the resource folder and you should be good to go.

CodePudding user response:

<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>3.0.2</version>
</dependency>

Add the above dependency.

  • Related