0

User_manager.java

package com.csc.trg.twit_clone.tweet_pack;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

public class User_Manager 
{

    public static void main(String[] args)

    {  
          //creating configuration object  
        Configuration cfg=new Configuration();  
        cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file         
        //creating session factory object     
        SessionFactory factory=cfg.buildSessionFactory();         
        //creating session object  
        Session session=factory.openSession();    
        //creating transaction object  
        Transaction t=session.beginTransaction();  
        User_Bean H =new User_Bean();
      H.setUserId(1001);  
        H.setUserName("visgf");  
        H.setUserPwd("passw");
       H.setEmailId("[email protected]");
       // session.persist(H);                   //persisting the object  
          session.save(H);

        t.commit();                         //transaction is committed  
        session.close(); 
        factory.close();

        System.out.println("successfully registered");  
        }
}

**user_bean**

package com.csc.trg.twit_clone.tweet_pack;
public class User_Bean
{

    int userId;
    String userName;
    String emailId;
    String userPwd;

public String getUserPwd() 
{
    return userPwd;
}
public void setUserPwd(String userPwd) 
{
    this.userPwd = userPwd;
}

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 getEmailId() 
{
    return emailId;
}
public void setEmailId(String emailId)
{
    this.emailId = emailId;
}

}

**hibernate.cfg.xml**

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

<hibernate-configuration>  

    <session-factory>  
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
        <property name="connection.url">jdbc:mysql://localhost/payrol</property>  
        <property name="connection.username">root</property>   
        <property name="connection.password">root</property>  
         <property name="show_url">true</property> 
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>        
         <property name="hbm2ddl.auto">update</property>  
    <mapping resource="twitt.hbm.xml"/>  
    </session-factory>  
</hibernate-configuration>  

**twit.hbm.xml**

<?xml version='1.0' encoding='UTF-8'?>  
<!DOCTYPE hibernate-mapping PUBLIC  
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
 "hibernate-mapping-3.0.dtd">  

 <hibernate-mapping>  

  <class name="com.csc.trg.twit_clone.tweet_pack.User_Bean" table="User_table">  
    <id name="userId">  
     <generator class="assigned"/>  
    </id>  
    <property name="userId" column="user_name" type="int" />
    <property name="userName" column="user_name" type="string" />  
       <property name="password" column="password" type="string" /> 
       <property name="emailId" column="email" type="String" />
  </class>            
 </hibernate-mapping>  

I'm trying to update the values to mysql database from java program using hibernate this is my first program in hibernate " I m getting this error plz help.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(email)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
    at org.hibernate.mapping.Property.isValid(Property.java:185)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
    at com.csc.trg.twit_clone.tweet_pack.User_Manager.main(User_Manager.java:21)

I have added both the tdd, configuration and mapping files in src. And added all the jars.

1

1 Answer 1

1

Please cross check the case of "string"in the config file.

<property name="password" column="password" type="string" /> 
<property name="emailId" column="email" type="String" />
Sign up to request clarification or add additional context in comments.

1 Comment

check this part wheather thats crct <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "hibernate-mapping-3.0.dtd"> and tell where to add that "hibernate-mapping-3.0.dtd" file its Dynamic web project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.