Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2013
    Posts
    69
    Rep Power
    0

    Default org.hibernate.MappingException: invalid configuration?

    I just started learning Hibernate and I have this problem.
    Exception in thread "main" org.hibernate.MappingException: invalid configuration
    at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:2158)
    at org.hibernate.cfg.Configuration.configure(Configur ation.java:2075)
    at org.hibernate.cfg.Configuration.configure(Configur ation.java:2054)
    at org.blerta.hibernate.HibernateMain.main(HibernateM ain.java:15)
    Caused by: org.xml.sax.SAXParseException; lineNumber: 28; columnNumber: 23; The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".


    My hibernate.cfg.xml file looks like this :
    Java Code:
        <!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>
        
         <!-- Database connection settings -->
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:MYTESTINSTANCE://localhost:1433;database=UserInfo</property>
        <property name="connection.username">Blerta-PC\Blerta</property>
        <property name="connection.password"></property>
        
       <!-- JDBC connection pool (use the built-in) -->
       <property name="connection.pool_size">1</property>
        
        <!-- SQL dialect -->
         <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
        
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        
         <!-- Drop and re-create the database schema on startup -->
         <property name="hbm2ddl.auto">create</property>
        
        <mapping class="org.blerta.hibernate.User"></mapping>
        
        </session-factory>
        
        </hibernate-configuration>
    This is User.java
    Java Code:
        package org.blerta.hibernate;
        
        import javax.persistence.Column;
        import javax.persistence.Entity;
        import javax.persistence.Id;
        
        @Entity(name="User_table")
        public class User {
         @Id
         int userId;
         @Column(name="User_Name")
         String userName;
         
         String userMessage;
         public int getUserId() {
          return userId;
         }
         public void setUserId(int userId) {
          this.userId = userId;
         }
         public String getUserName() {
          return userName;
         }
         public void setUserName(String userName) {
          this.userName = userName;
         }
         public String getUserMessage() {
          return userMessage;
         }
         public void setUserMessage(String userMessage) {
          this.userMessage = userMessage;
         }
          
        }
    And this is my main class:
    Java Code:
        package org.blerta.hibernate;
        
        import org.hibernate.Session;
        import org.hibernate.SessionFactory;
        import org.hibernate.cfg.Configuration;
        import org.hibernate.service.ServiceRegistry;
        import org.hibernate.service.ServiceRegistryBuilder;
        
        @SuppressWarnings("deprecation")
        public class HibernateMain {
        
         public static void main(String[] args) {
            
          Configuration configuration = new Configuration();
          configuration.configure();
          ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
          SessionFactory sf = configuration.buildSessionFactory(sr);
          
          User user1 = new User();
          user1.setUserName("Blerta");
          user1.setUserMessage("Hello world from Blerta");
          
          User user2 = new User();
          user2.setUserName("Silva");
          user2.setUserMessage("Hello world from Silva");
          Session ss = sf.openSession();
          ss.beginTransaction();
         //saving objects to session
          ss.save(user1);
          ss.save(user2);
          ss.getTransaction().commit();
          ss.close();
          
         }
        
        }
    I think what I'm doing wrong is the way I specify the instance of my sql server:
    This is a snapshoot :
    org.hibernate.MappingException: invalid configuration?-untitled.png

    Thanks in advance...

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,048
    Rep Power
    6

    Default Re: org.hibernate.MappingException: invalid configuration?

    I don't see anything wrong with the file. Apparently the XML parser and validator thinks you have an element in your session-factory that should not be in there, but what you posted is according to the rules. The only thing I spot is that your session-factory is missing a name attribute as demonstrated in the documentation:

    Chapter¬*3.¬*Configuration

    Are you sure that what you posted is the file that Hibernate is seeing? Where did you put this file?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Jan 2013
    Posts
    69
    Rep Power
    0

    Default Re: org.hibernate.MappingException: invalid configuration?

    Yes I am completely sure ...
    This is how my project hierarchy looks like
    org.hibernate.MappingException: invalid configuration?-untitled.png

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,048
    Rep Power
    6

    Default Re: org.hibernate.MappingException: invalid configuration?

    Yeah that's alright. Well then I'm clueless, sorry to say. At this point I'd start fiddling. Remove the comments and empty lines, make sure the formatting is alright (with CTRL+SHIFT+F you can auto-format a file in Eclipse).

    Also do a sanity check: open up the project settings (right click on HibernateHelloWorldProject, properties) and check the build path to make sure that Eclipse hasn't put conflicting inclusion/exclusion rules in your source tree.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Join Date
    Jan 2013
    Posts
    69
    Rep Power
    0

    Default Re: org.hibernate.MappingException: invalid configuration?

    I did all the things you suggested, but the exactly same problem persists

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,048
    Rep Power
    6

    Default Re: org.hibernate.MappingException: invalid configuration?

    Sorry to hear it. I can't help you.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Join Date
    Jan 2013
    Posts
    69
    Rep Power
    0

    Default Re: org.hibernate.MappingException: invalid configuration?

    Thanks anyway

Similar Threads

  1. Replies: 2
    Last Post: 10-23-2013, 09:36 AM
  2. Replies: 1
    Last Post: 09-11-2013, 02:48 PM
  3. Replies: 3
    Last Post: 08-30-2012, 06:24 PM
  4. Replies: 1
    Last Post: 06-21-2011, 12:50 PM
  5. Could not parse configuration: /hibernate.cfg.xml
    By Matang in forum Web Frameworks
    Replies: 2
    Last Post: 04-10-2011, 02:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •