- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在学习 hibernate,无法从 oracle 获取数据。非常感谢任何帮助。
请找到下面的配置文件、pojo类和main方法...
hibernate .cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="hibernate.connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.connection.url">
jdbc:oracle:thin:***
</property>
<property name="hibernate.connection.username">
***
</property>
<property name="hibernate.connection.password">
***
</property>
<mapping resource="tutorialspoint/example/Pojo_S.hbm.xml" />
</session-factory>
</hibernate-configuration>
Pojo 类
package tutorialspoint.example;
public class Pojo_S {
int SId;
String SCode;
String SName;
public int getSId() {
return SId;
}
public void setSId(int SId) {
SId = SId;
}
public String getSCode() {
return SCode;
}
public void setSCode(String SCode) {
SCode = SCode;
}
public String getSName() {
return SName;
}
public void setSName(String SName) {
SName = SName;
}
}
Pojo_S.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tutorialspoint.example.Pojo_S" table="S">
<id name="SId" type="int" column="S_ID">
<generator class="native" />
</id>
<property name="SCode" column="S_CODE" type="string" />
<property name="SName" column="S_NAME" type="string" />
</class>
</hibernate-mapping>
主要方法
package tutorialspoint.example;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class MainApp {
private static SessionFactory factory;
public static void main(String[] args) {
try{
System.out.println("In Main method of MainApp...");
Configuration configure=new Configuration();
configure.configure("hibernate.cfg.xml");
factory = configure.buildSessionFactory();
MainApp mainApp = new MainApp();
mainApp.listDetails_S();
}
catch(Throwable ex){
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public void listDetails_S(){
System.out.println("In listDetails_S method of MainApp...");
Session session = factory.openSession();
Transaction tx = null;
try{
List details = session.createQuery("FROM S").list();
for (Iterator iterator = details.iterator(); iterator.hasNext();){
Pojo_S detail = (Pojo_S) iterator.next();
System.out.print("\nSId: " + detail.getSId());
System.out.print("\nSCode: " + detail.getSCode());
System.out.print("\nSName: " + detail.getSName());
}
tx.commit();
}
catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
错误日志
In Main method of MainApp...
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2 cr4
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: tutorialspoint/example/Pojo_S.hbm.xml
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: tutorialspoint.example.Pojo_S -> S
Mar 10, 2016 12:06:11 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Mar 10, 2016 12:06:12 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Mar 10, 2016 12:06:12 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Mar 10, 2016 12:06:12 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Mar 10, 2016 12:06:12 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:****
Mar 10, 2016 12:06:12 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=***, password=****}
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 11.2.0.2.0
Mar 10, 2016 12:06:41 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.OracleDialect
Mar 10, 2016 12:06:41 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Mar 10, 2016 12:06:41 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)
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Mar 10, 2016 12:06:41 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Mar 10, 2016 12:06:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Mar 10, 2016 12:06:41 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
In listDetails_S method of MainApp...
Mar 10, 2016 12:06:41 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
org.hibernate.hql.ast.QuerySyntaxException: S is not mapped [FROM S]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:265)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at tutorialspoint.example.MainApp.listDetails_S(MainApp.java:42)
at tutorialspoint.example.MainApp.main(MainApp.java:24)
}
最佳答案
显然,错误在这里
List details = session.createQuery("FROM S").list();
在 HQL 中你需要使用持久类名,而不是表名。
List details = session.createQuery("FROM Pojo_S").list();
而且你可以使用更简单的代码
List<Pojo_S> details = session.createQuery("FROM Pojo_S").list();
for (Pojo_S detail : details){
System.out.print("\nSId: " + detail.getSId());
System.out.print("\nSCode: " + detail.getSCode());
System.out.print("\nSName: " + detail.getSName());
}
关于java - 信息 : Not binding factory to JNDI, 未配置 JNDI 名称 org.hibernate.hql.ast.QuerySyntaxException:<TableName> 未映射 [FROM <TableName>],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909725/
有没有办法定义命名参数(不是模型属性)来控制 factory.Maybe 的行为? 例如:我想创建一个命名参数,通过可能条件控制RelatedFactory的创建,我尝试这样做: # factorie
我正在阅读有关创 build 计模式的文章,并且设法将自己完全混淆在工厂、抽象工厂和工厂方法之间。 我在下面发布了一个代码片段。是否有人可以告诉我这是哪一个以及(如果可能)可以对代码进行哪些更改以使其
我正在尝试让 Factory Girl 正常工作,但在运行测试时我不断收到此错误: /Users/dm/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1
有两个公共(public)接口(interface): LayoutInflater.Factory和 LayoutInflater.Factory2在 android sdk 中,但官方文档无法说明
在我们针对 rails 3.1.0 应用程序的 rspec 测试中,我们同时使用了 Factory.build 和 Factory.attributes_for。我们发现,如果我们将 Factory.
我想创建一个 ADF v2 管道来调用 Azure SQL 数据库中的存储过程。存储过程有输入参数并会返回多个结果集(大约 3 个)。我们需要把它提取出来。我们正在尝试加载到 4 个不同文件的 Blo
注意:问题位于帖子末尾。 我已经阅读了有关抽象工厂与工厂方法的其他 stackoverflow 线程。我理解每种模式的意图。不过我不太清楚这个定义。 Factory Method defines an
如何将 :subscriber factory 中的“email”属性值传递给它的关联:authentication 例如: factory :subscriber, :class => Subscr
我正在使用 Factory Boy为我的 Django 应用程序创建测试工厂。我遇到问题的模型是一个非常基本的帐户模型,它与 django 用户身份验证模型(使用 django < 1.5)具有 On
假设我们有一个 I/O 绑定(bind)方法(例如进行数据库调用的方法)。此方法既可以同步运行,也可以异步运行。也就是说, 同步: IOMethod() 异步: BeginIOMethod() End
我正在开发基于 Spring Boot Batch XML 的方法。在此示例中,我开发了一个如下所示的 CommonConfig。不知何故,我想对 Spring Batch 使用基于 XML 的方法,
更新 回答如下。万一链接站点消失,您可以使用 mocha stub 初始状态并防止覆盖,如... require 'mocha' class OrderTest "other_state") e
我有一个非常简单的 Rails 4 应用程序,想使用 Factory Girl 编写一些示例测试。该应用程序适用于一些简单的 rspec 测试(全部通过),但是当我将“factory_girl_rai
我们的要求是从 Blob 存储中获取数据并转换为其他表格形式。这可以通过使用 polybase 的 Sql DW 来实现。在这种情况下,Azure 数据工厂的真正作用是什么? 我知道 Azure 数据
如何解决Spring中Bean的自动连接歧义?我们有一个 Dessert 接口(interface),并且有实现该接口(interface)(Dessert)的三种不同的甜点(Bean)。 今天的甜点
我目前正在使用 RSpec 和 Factory_Bot_Rails gem 来测试应用程序,但我遇到了以下问题。 当使用 factory_bot_rails 版本 5.0.2 gem 时,我的工厂现在
我有下面的简化代码,可以异步获取多个承运人的运费,我想知道是否值得转换为使用异步/等待方法,如果是的话,最好的方法是什么?或者如果它现在工作正常,真的不值得付出努力吗?谢谢。 List> lstTas
我是初学者,正在尝试运行第一个简单的代码。 请帮我解决以下问题。 Error on line 11 of document : The element type "session-factory"
我正在寻求使我的 Rails 测试更快。我只有 520 个测试,但它们在 bash 中运行需要 62 秒,在 Rubymine 中运行需要 82 秒。 作为典型 Controller 测试的示例,我使
我们计划使用 IBM Web Experience Factory 来进行 future 的增强。从项目管理的角度来看我们正在考虑使用Maven。但由于没有在线帮助来同时使用这两个东西,我们无法继续前
我是一名优秀的程序员,十分优秀!