正如我在标题中写的那样,我有特定的问题: 上传数据正在运行但阅读却给了我这样的错误:
TableMetadata:62 - table found: baza.przychodzace INFO
TableMetadata:63 - columns: [id, wydzial, imie, adres, tekst, data,
miasto, data2, nazwisko, sygnatura] Exception in thread
"AWT-EventQueue-0" org.hibernate.hql.ast.QuerySyntaxException:
przychodzace is not mapped [from przychodzace]
数据库架构:
CREATE TABLE IF NOT EXISTS `przychodzace` ( `ID` int(11) NOT NULL
AUTO_INCREMENT, `IMIE` varchar(32) CHARACTER SET utf8 COLLATE
utf8_bin NOT NULL, `NAZWISKO` varchar(32) CHARACTER SET utf8 COLLATE
utf8_bin NOT NULL, `MIASTO` varchar(32) CHARACTER SET utf8 COLLATE
utf8_bin NOT NULL, `ADRES` varchar(32) CHARACTER SET utf8 COLLATE
utf8_bin NOT NULL, `DATA` date NOT NULL, `DATA2` date NOT NULL,
`WYDZIAL` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`SYGNATURA` varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`TEKST` varchar(3000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf32
COLLATE=utf32_polish_ci AUTO_INCREMENT=4 ;
hibernate.cf:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/baza</property>
<property name="connection.username">root</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.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<mapping resource="xml/maps/Maps.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Maps.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="xml.maps">
<class name="przychodzace.model.PrzychodzaceModel" table="przychodzace">
<id name="przychodzaceId" column="ID">
<generator class="native"/>
</id>
<property name="imie" column="IMIE"/>
<property name="nazwisko" column="NAZWISKO"/>
<property name="miasto" column="MIASTO"/>
<property name="adres" column="ADRES"/>
<property name="data" type="date" column="DATA"/>
<property name="data2" type="date" column="DATA2"/>
<property name="wydzial" column="WYDZIAL"/>
<property name="sygnatura" column="SYGNATURA"/>
<property name="tekst" column="TEKST"/>
</class>
</hibernate-mapping>
PrzychodzaceControler.java where everythings happen
public void zapis(PrzychodzaceModel model) {
model = save(model);
}
public List<PrzychodzaceModel> read() {
HibernateUtil hib = new HibernateUtil();
return list();
}
private static List list() {
SessionFactory sf = HibernateUtil.getSessionFactory();
Session session = sf.openSession();
List przychodzace = session.createQuery("from przychodzace").list();
System.out.println(przychodzace.size() + "size");
session.getTransaction().commit();
session.close();
return przychodzace;
}
private static PrzychodzaceModel save(PrzychodzaceModel model) {
SessionFactory sf = HibernateUtil.getSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
int id = (Integer) session.save(model);
model.setPrzychodzaceId(id);
session.getTransaction().commit();
session.close();
return model;
}
Thanks in advance i have no idea what can be wrong
答案 0 :(得分:2)
更改
session.createQuery("from przychodzace").list();
到
session.createQuery("from "+PrzychodzaceModel.class.getSimpleName()).list();
您正在使用hql
您必须使用类名而不是表名。