- 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/
我是 JNDI 的新手,我阅读了 oracle 的在线资料: http://docs.oracle.com/javase/jndi/tutorial/getStarted/overview/index
什么是JNDI? 它的基本用途是什么? 什么时候使用? 最佳答案 What is JNDI ? 它代表Java Naming and Directory Interface . What is its
我有完整的应用服务器背景,并考虑在 Jetty 等轻量级嵌入式服务器上运行应用。 我一直使用 JNDI 来查找连接池以查找数据库连接之类的东西,但我想知道这是否是轻量级案例的最佳方法。似乎如果我使用
您如何使用 JDBCRealm处理servlet 中的用户身份验证和授权?我能找到的唯一示例是在 web.xml 中创建数据源(例如 Authentication against database u
命名和目录 (JNDI) - 使用 JNDI 的陷阱是什么 最佳答案 这个问题有点含糊,但这里有几点需要考虑并且与 JNDI 相关。 JNDI 的好处是对象创建与对象查找分离 在 JDNI 中直接查找
在 Wildfly 9 中显示注册的 JNDI 名称的正确方法是什么? 对于旧版本,可以使用 /subsystem=naming:jndi-view ,但它似乎不再起作用。在域模式下运行时。 感谢帮助
我有两个 JBoss 服务器,JbossA 和 JbossB。每个都有自己的 JNDI。现在我在 JbossA 上有一个名为 jms/Client 的 JMS,在 JbossB 上有一个名为 jms/
这是我的“hibernate.cfg.xml”,我正在尝试连接到我的本地主机(postgres),但我不确定我是否输入了参数值(例如连接 url 或其他) : org.hiber
是否可以通过 JNDI 访问 Wildfly 属性(在 standalone.xml 中定义)? 喜欢: ... 并在java中阅读它: @Resource(lo
第126章OSGI Enterprise Release 5 specification提到兼容性: "Support the traditional JNDI programming model u
import org.apache.catalina.Context; import org.apache.catalina.deploy.ContextResource; import org.ap
在我们的项目中,我们使用 websphere liberty 服务器和 IBM MQ 作为消息服务器。我们在云中移动。我们想用 AWS SQS 替换 IBM MQ。在 server.xml 中,我们有
似乎每个人都说您应该使用 Tomcat 的 JNDI 上下文来管理您的 JDBC 连接和驱动程序等等。在阅读了文档之后,我理解了平局。但是,如果您使用它,您的应用程序必须从现在开始一直使用 Tomca
我正在 JBoss7.1.1 应用程序服务器上部署我的 MDB (EJB3.1)。当我使用@Resource进行数据源注入(inject)时,我使用全局JNDI引用名称(ENC +本地JNDI引用名称
使用 JBoss eap 6.4.12 出现错误: Error looking up ${email.jndi.lookup.binding} in JNDI 在我的 java 类中映射此 JNDI
使用com.sun.jndi.fscontext.RefFSContextFactory基于文件的 JNDI 上下文工厂,它似乎只允许在您指定的位置有 1 个绑定(bind)文件。例如 Hashtab
这是我的persistence.xml: org.hibernate.ejb.HibernatePersistence jdbc/abcDS 这是来自 src/test
我已经为我的模块之一运行了强化扫描,我已经收到了 动态代码评估:JNDI 引用注入(inject)漏洞问题 显示在下一行 lookup(dataSource) 数据源是动态的。我应该怎么做才能防止这种
我有 EJB 3.1 中的 EJB,我试图将其部署在 JBoss EAP 6 中,但是当我启动服务器时。它在 JNDI 名称中附加版本号,如下所示。 18:27:57,068 INFO [org.j
我有一个测试,它成功地使用嵌入式 glassfish 来测试 JCA 的部署。 但是,与已经在使用端口 3700 的 GlassFish 2.1 的运行版本存在冲突。 如何将嵌入的 GlassFish
我是一名优秀的程序员,十分优秀!