0

enter image description here

i am doing hibernate sample in java.below is code used

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.driver_class">com.mysql.jdbc.Driver</property>
 <property name="hibernate.connection.password">root</property>
 <property    name="hibernate.connection.url">jdbc:mysql://localhost:3306/serverdata</property>
  <property name="hibernate.connection.username">root</property>
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
 <property name="hibernate.connection.autocommit">false</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
 <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
 <mapping  resource="table.hbm.xml"/>
 </session-factory>
 </hibernate-configuration>

table.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
 <hibernate-mapping>  
 <class name="tabledata" table="tabledata">  
 <id name="id" column="id" type="ïnteger">  
 <generator class="assigned"></generator>  
 </id>  

  <property name="Name"  column="Name" type="string"></property>  
        </class>  
      </hibernate-mapping>    

inserttable.java

public class Inserttable {

public static void main(String[] args) {
    // TODO Auto-generated method stub
Configuration cfg = new Configuration();
cfg.configure("Hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
tabledata tab = new tabledata();
tab.setId(1);
tab.setName("mack");
s.save(tab);
s.flush();
tx.commit();
s.close();}
}

i am using mysql database so i am using mysql-connector and below are the following jar used

mysql-connector-java-5.1.38-bin.jar
antlr-2.7.6.jar
cglib-2.2.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
Hibernate3.jar
Hibernate-jpa-2.0-api-1.0.0.Final.jar
Hibernate-Testing.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
ehcache-1.2.3.jar
slf4j-jdk14-1.5.8.jar
slf4j-api-1.5.8.jar
commons-logging-1.0.4.jar

it shows below error

 Dec 26, 2015 6:32:31 PM org.hibernate.annotations.common.Version <clinit>
 INFO: Hibernate Commons Annotations 3.2.0.Final
 Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.6.4.Final
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
 Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment buildBytecodeProvider
 INFO: Bytecode provider name : javassist
 Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
 INFO: using JDK 1.4 java.sql.Timestamp handling
  Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration configure
  INFO: configuring from resource: Hibernate.cfg.xml
  Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration       getConfigurationInputStream
  INFO: Configuration resource: Hibernate.cfg.xml
  Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration addResource
 INFO: Reading mappings from resource : firsthb/table.hbm.xml
 Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration doConfigure
 INFO: Configured SessionFactory: null
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.HbmBinder    bindRootPersistentClassCommonValues
 INFO: Mapping class: tabledata -> tabledata
 Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration   applyHibernateValidatorLegacyConstraintsOnDDL
 INFO: Hibernate Validator not found: ignoring
 Dec 26, 2015 6:32:31 PM    org.hibernate.cfg.search.HibernateSearchEventListenerRegister    enableHibernateSearch
 INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener   on the classpath. Hibernate Search is not enabled.
 Dec 26, 2015 6:32:31 PM   org.hibernate.connection.DriverManagerConnectionProvider configure
 INFO: Using Hibernate built-in connection pool (not for production use!)
 Dec 26, 2015 6:32:31 PM  org.hibernate.connection.DriverManagerConnectionProvider configure
 INFO: Hibernate connection pool size: 20
  Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
  INFO: autocommit mode: false
   Dec 26, 2015 6:32:31 PM  org.hibernate.connection.DriverManagerConnectionProvider configure
  INFO: using driver: com.mysql.jdbc.Driver at URL:   jdbc:mysql://localhost:3306/serverdata
  Dec 26, 2015 6:32:31 PM    org.hibernate.connection.DriverManagerConnectionProvider configure
   INFO: connection properties: {user=root, password=****, autocommit=false}
   Sat Dec 26 18:32:31 IST 2015 WARN: Establishing SSL connection without    server's identity verification is not recommended. According to MySQL 5.5.45+,     5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if   explicit option isn't set. For compliance with existing applications not using   SSL the verifyServerCertificate property is set to 'false'. You need either to    explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide    truststore for server certificate verification.
  Dec 26, 2015 6:32:32 PM org.hibernate.dialect.Dialect <init>
  INFO: Using dialect: org.hibernate.dialect.MySQLDialect
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Database ->
   name : MySQL
version : 5.7.10-log
  major : 5
  minor : 7
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Driver ->
   name : MySQL Connector Java
version : mysql-connector-java-5.1.38 ( Revision:    fe541c166cec739c74cc727c5da96c1028b4834a )
  major : 5
  minor : 1
 Dec 26, 2015 6:32:32 PM org.hibernate.transaction.TransactionFactoryFactory  buildTransactionFactory
 INFO: Transaction strategy:   org.hibernate.transaction.JDBCTransactionFactory
 Dec 26, 2015 6:32:32 PM  org.hibernate.transaction.TransactionManagerLookupFactory  getTransactionManagerLookup
  INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Automatic flush during beforeCompletion(): disabled
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Automatic session close at end of transaction: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: JDBC batch size: 15
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: JDBC batch updates for versioned data: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Scrollable result sets: enabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: JDBC3 getGeneratedKeys(): enabled
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Connection release mode: auto
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
  INFO: Maximum outer join fetch depth: 2
   Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
   INFO: Default batch fetch size: 1
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Generate SQL with comments: enabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Order SQL updates by primary key: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
  INFO: Order SQL inserts for batching: disabled
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory     createQueryTranslatorFactory
  INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
   Dec 26, 2015 6:32:32 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
   INFO: Using ASTQueryTranslatorFactory
   Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
   Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
   INFO: JPA-QL strict compliance: disabled
   Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Query cache: disabled
  Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory createRegionFactory
    INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
  INFO: Optimize cache for minimal puts: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Structured second-level cache entries: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Echoing all SQL to stdout
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Statistics: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Deleted entity synthetic identifier rollback: disabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Default entity-mode: pojo
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
 Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
 INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Dec 26, 2015 6:32:32 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
 Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [materialized_clob] overrides previous :        org.hibernate.type.MaterializedClobType@133e16fd
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [clob] overrides previous : org.hibernate.type.ClobType@51b279c9
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@51b279c9
 Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
 INFO: Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@1ad282e0
  Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
  INFO: Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@7f416310
 Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
 INFO: Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@1cab0bfb
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
 INFO: Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@5e955596
 Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
 INFO: Type registration [blob] overrides previous :    org.hibernate.type.BlobType@50de0926
 Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
 INFO: Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@50de0926
  Exception in thread "main" org.hibernate.MappingException: entity class not found: tabledata
at    org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:125)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>   (EntityMetamodel.java:135)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>   (AbstractEntityPersister.java:485)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init> (SingleTableEntityPersister.java:133)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at firsthb.Inserttable.main(Inserttable.java:16)
 Caused by: java.lang.ClassNotFoundException: tabledata
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at    org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
... 9 more

Please help me to know whats the problem in my code or is it about jar files added.let me know,any help is appreciated.

EDIT: Also replace with in tabledata.hbm.xml after this it works.I think this will be good example for hibernate learning beginners.

allDroid
  • 405
  • 1
  • 10
  • 21

2 Answers2

1

Your folder does follow the right conventions

Resource files should be under src/main/resources

java files under src/main/java

Though its not mandatory to follow but you should as some of your issues will automatically go away and then you are moving towards convention over configuration. Otherwise you can do below as hfg file will be able to search the hbm file from right folder

M Sach
  • 33,416
  • 76
  • 221
  • 314
0

In your file Hibernate.cfg.xml add this

<mapping  resource="firsthb/table.hbm.xml"/>
  • i get like this error what does it mean Exception in thread "main" org.hibernate.MappingException: Could not determine type for: ïnteger, at table: tabledata, for columns: [org.hibernate.mapping.Column(id)] – allDroid Dec 26 '15 at 12:54
  • you should replace "ïnteger" by "integer" – Safouen Ferchichi Dec 26 '15 at 13:02
  • after replacing i get errors as updated above whats going wrong? – allDroid Dec 26 '15 at 13:23
  • worked after giving fully qualified class name (with package) http://stackoverflow.com/questions/6692882/hibernateerror-entity-class-not-found.In my case i have to give in table.hbm.xml . – allDroid Dec 26 '15 at 13:43