0
我有休眠創建我的數據庫模式。它能夠很好地創建表,但指定的查詢不會編譯,因爲它聲明對象未映射。Hibernate無法找到它剛剛創建的表的類的映射
整個應用程序是註釋和配置驅動:沒有.xml
文件。
下面是相關配置部分:
properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
properties.setProperty("hibernate.connection.url", con);
properties.setProperty("hibernate.connection.username", user);
properties.setProperty("hibernate.connection.password", pass);
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.setProperty("hibernate.current_session_context_class","thread");
properties.setProperty("hibernate.hbm2ddl.auto","create");
Configuration config = new Configuration();
config.setProperties(properties);
config.addAnnotatedClass(Player.class);
SessionFactory factory = config.buildSessionFactory();
我的播放器類已初具雛形,現在 - 它有一個像姓名和身份證一些參數。它高興地將這些轉換成適當的表格。
@Entity
@NamedQueries({
@NamedQuery(name="verifyPlayerByUuid", query="SELECT name FROM player WHERE uuid = :uuid"),
@NamedQuery(name="verifyPlayerByName", query="SELECT name FROM player WHERE name = :name"),
@NamedQuery(name="obtainPlayerByUuid", query="FROM player WHERE uuid = :uuid"),
})
public class Player {
// impl here
}
當我運行它,我得到這個。請注意,我修剪了樣板時間戳和休眠包名稱,以便爲相關消息留出更多空間。爲了更好地組織數據,我還採取了格式化信息的自由 - 這隻涉及空白的添加。
[timestamp] [hib].hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schema export
[timestamp] [hib].hbm2ddl.SchemaExport - HHH000230: Schema export complete
[timestamp] [hib].SessionFactoryImpl - HHH000177: Error in named query: verifyPlayerByUuid
org.hibernate.hql.internal.ast.QuerySyntaxException:
player is not mapped [SELECT name FROM player WHERE uuid = :uuid]
[timestamp] [hib].SessionFactoryImpl - HHH000177: Error in named query: obtainPlayerByUuid
org.hibernate.hql.internal.ast.QuerySyntaxException:
player is not mapped [FROM player WHERE uuid = :uuid]
[timestamp] [hib].SessionFactoryImpl - HHH000177: Error in named query: verifyPlayerByName
org.hibernate.hql.internal.ast.QuerySyntaxException:
player is not mapped [SELECT name FROM player WHERE name = :name]
所以HQL區分大小寫? – corsiKa
@corsiKa是的,非常非常。否則反思將無法正常工作。 –
@corsiKa也可能是相關的:http://stackoverflow.com/questions/5327682/hql-with-fully-qualified-class-name –