简体   繁体   中英

Could not determine type for: String, at table: STUDENT, for columns: [org.hibernate.mapping.Column(SNAME)]

how to resolve this exception... please help me... while I am executing this simple hibernate programme. I am getting this exception :

Exception in thread "main" org.hibernate.MappingException: Could not determine type for: String, at table: STUDENT, for columns: [org.hibernate.mapping.Column(SNAME)]

mapping file:

<?xml version = "1.0" encoding = "utf-8"?>

<hibernate-mapping>
<class name = "Student" table = "STUDENT" >
    <meta attribute="Class description">
        This contains Student details.
    </meta>
    <id name="id" type="int" column="id">
        <generator class="native"/>
    </id>
    <property name="name" column="SNAME" type="String"/>
    <property name="mNo" column="MNO" type="String"/>
    <property name="marks" column="MARKS" type="String"/>

</class>

configuration file:

<?xml version = "1.0" encoding = "utf-8"?>

<hibernate-configuration>
<session-factory>
    <!-- <property name="hibernate.dialect">org.hibernate.dialect.MySQLdialect</property> -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/firsthibernate</property>
    <property name="hibernate.connection.user">root</property>
    <property name="hibernate.connection.password">asdf</property>
    <mapping resource="Student.hbm.xml"/>
</session-factory>

Pojo class:

public class Student {
private int id;
private String name;
private String mNo;
private String marks;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getmNo() {
    return mNo;
}
public void setmNo(String mNo) {
    this.mNo = mNo;
}
public String getMarks() {
    return marks;
}
public void setMarks(String marks) {
    marks = marks;
}

}

Test class:

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



public class DemoStudent {

public static void main(String[] args) {
    Student st=new Student();
    st.setId(1);
    st.setName("Amit");
    st.setmNo("8927070972");
    st.setMarks("98%");

    Configuration cfg=new Configuration();
    cfg.configure();
    SessionFactory sf=cfg.buildSessionFactory();
    Session s=sf.openSession();
    Transaction tr=s.beginTransaction();
    tr.begin();
    s.save(st);
    tr.commit();

}

}

Thanks in advance... while I am executing this simple hibernate programme. I am getting this please help me where I am doing mistake in this programme.

In hibernate mapping file use type as string instead of String.

<property name="name" column="SNAME" 
type="string"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM