Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:54+00:00 2026-05-16T23:27:54+00:00

Right now i want to make a small java application, in order to learn

  • 0

Right now i want to make a small java application, in order to learn the hibernate framework. But it gives me the org.hibernate.MappingException: Repeated column in mapping for entity: model.Book column: author (should be mapped with insert="false" update="false"). And if I delete the author column mapping from entities.hbm.xml, then it shows me that sql message “SELEC FROM …” but after that, it gives me 2 exceptions:

  • org.hibernate.exception.GenericJDBCException: could not execute query
  • java.sql.SQLException: No database selected.

Can anyone help me?

hibernate.cfg.xml file:

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

<hibernate-configuration>
<session-factory>

    <property name = "hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name = "hibernate.connection.url">jdbc:mysql://127.0.0.1:3306</property>
    <property name = "hibernate.connection.username">root</property>
    <property name = "hibernate.connection.password"></property>
    <property name = "hibernate.connection.pool_size">10</property>
    <property name = "dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name = "hibernate.hbm2ddl.auto">update</property>
    <property name = "show_sql">true</property>

    <mapping resource = "entities.hbm.xml"/>

</session-factory>
</hibernate-configuration>

entities.hbm.xml file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package = "model">

   <class name = "Genre" table = "virtual bookcase.genres">
      <id name = "id" column = "idGenres" type = "long">
        <generator class = "increment"/>
      </id>   
      <property name = "name" column = "name" type = "string"/>
      <set name = "books" table = "books" cascade = "all-delete-orphan">
        <key column = "idGenres" not-null = "true" />
        <one-to-many class = "Book"/>
      </set>
   </class>

   <class name = "Book" table = "virtual bookcase.books">
        <id name = "id" column = "idBooks" type = "long">
         <generator class = "increment"/>
        </id>
        <property name = "title" column = "title" type = "string"/>
        <property name = "author" column = "author" type = "string"/>
        <property name = "publisher" column = "author" type = "string"/>
        <property name = "pages" column = "pages" type = "short"/>
        <property name = "borrowed" column = "borrowed" type = "byte"/>
        <property name = "borrowedTo" column = "borrowedTo" type = "string"/>
   </class>

</hibernate-mapping>

Java entities:

public class Genre
{
    private long id;
    private String name;
    private Set<Book> books;

    public long getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Set<Book> getBooks()
    {
        return books;
    }

    public void setBooks(Set<Book> books)
    {
        this.books = books;
    }

    @Override
    public String toString()
    {
        return name;
    }
}

getBooks() method:

public Set<Book> getBooks()
    {
        Set<Book> books = null;

        connect();

        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session s = sf.openSession();

        Query q = s.createQuery("FROM Book");
        books = new TreeSet<Book>(q.list());

        for (Book b : books)
            System.out.println(b);

        s.close();
        sf.close();

        disconnect();

        return books;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:27:55+00:00Added an answer on May 16, 2026 at 11:27 pm

    You have two properties mapped to the column author:

    <property name="author" column="author" type="string"/>
    <property name="publisher" column="author" type="string"/>
    

    To solve the second error append the database name to your JDBC connection URL:

    <property name="hibernate.connection.url">
        jdbc:mysql://127.0.0.1:3306/dbname
    </property>
    

    Reading through your sources further I stumbled over your getBooks()-method. You should not create a SessionFactory every time you need a Hibernate Session. The creation of the SessionFactory is too expensive (measured in time) to perform this every time. A minimum solution would be a Singleton class you can ask for the SessionFactory:

    public class SessionFactoryUtil {
    
        private static SessionFactory sessionFactory;
    
        private SessionFactoryUtil() {}
    
        static {
           sessionFactory = new Configuration().configure().buildSessionFactory();
        }
    
        public static SessionFactory getInstance() { return sessionFactory; }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to java and develeping a small application in java, right now
I'm currently trying to make a small application that performs different duties. Right now
I want to make an ad banner. Right now i have an imagebutton that
Right now I am using sqlite within a ios application, and I want to
right now its set up to write to a file, but I want it
Right now I use a StackPanel where I have a small image but I
I normally make multiple small edits to my source code, but I don't want
I want to make a small web application, and I'm not sure how to
so I'm in a little over my head right now and want to verify
I've created a custom view class and right now just want to draw an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.