Connecting to hibernate
Hi
My web application is a JSF application and it uses hibernate (ORM) to hide DB details from the webdeveloper , so he directly works with POJOs.
I know that CR4E enables me to work with POJOs , so my questions are:
1- How can i work with POJOs using PUSH method ? (note : i'm using JSP pages under JSF framework)
2- Can i work with POJOs using the PULL method (so i don't prepare any objects in advance and let the report ask for them "somehow" ) ?
3- is it possible to use HQL (hibernate query language) instead of SQL in the reports.
4- in the PUSH or PULL method , i want the DB querying to be on demand when the user navigate to the pages , as there are scenarios where the report should contain man results , but the user will just see the first page and will close the report , so i don't want the report to load all the data from the database at the start up , i want it to load the data of the first page only , and the rest will be on demand.
Thanks ,
Joseph
chang75 wrote:
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:XE, "system", "mypass50";what do you think the SID is in the URL you provided?
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:XE, "system", "mypass50";
</property> ...
And what do you think it should be?
Similar Messages
-
Bluetooth mouse does not connect after hibernate
Mouse cklick 406S connecting with my macbook pro 15' OS Lion 10.7.2 (second half of 2011).
After 5 minutes motionless mouse not connected.
Also, if laptop reboot, it not connected too. I'm read most of the posts from this site, but have not found a solution.
I need help. Thanks in advance.Hello!
My preferences http://grrrab.it/er612u and advanced http://grrrab.it/m981gp -
Hibernate query...how to connect two databases...
hi i m new to hibernate..
i created two tables..
1st table is catalog:
2nd table is acctinfo
//HBM file is :
<?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>
<class name="hibernate.example.Catalog" table="catalog">
<id name="id" type="integer" column="ID">
<generator class="increment"/>
</id>
<property name="journal" type="string" column="JOURNAL"/>
<property name="publisher" type="string" column="PUBLISHER"/>
<property name="edition" type="string" column="EDITION"/>
<property name="title" type="string" column="TITLE"/>
<property name="author" type="string" column="AUTHOR"/>
<bag name="accinfo" cascade="all" >
<key column="ID"/>
<one-to-many class="hibernate.example.Acctinfo"/>
</bag>
</class>
<class name="hibernate.example.Acctinfo" table="acctinfo">
<id name="id" type="integer" column="ID">
<generator class="increment"/>
</id>
<property name="account" type="string" column="ACCOUNT"/>
<property name="password" type="string" column="PASSWORD"/>
<property name="balance" type="string" column="BALANCE"/>
</class>
</hibernate-mapping>
///******************getter setter file is::****************
package hibernate.example;
public class Acctinfo
int id;
String account;
String password;
String balance;
public Acctinfo()
public void setId(int id)
this.id = id;
public int getId()
return id;
public void setAccount(String account)
this.account = account;
public void setPassword(String password)
this.password = password;
public void setBalance(String balance)
this.balance = balance;
public String getAccount()
return account;
public String getBalance()
return balance;
public String getPassword()
return password;
//********************2nd getter setter file is:***********************
package hibernate.example;
import java.util.List;
public class Catalog
int id;
String journal;
String publisher;
String edition;
String title;
String author;
private List accinfo;
public Catalog()
public void setId(int id)
this.id = id;
public int getId()
return id;
public void setJournal(String journal)
this.journal = journal;
public String getJournal()
return journal;
public void setPublisher(String publisher)
this.publisher = publisher;
public String getPublisher()
return publisher;
public void setEdition(String edition)
this.edition = edition;
public String getEdition()
return edition;
public void setTitle(String title)
this.title = title;
public String getTitle()
return title;
public void setAuthor(String author)
this.author = author;
public String getAuthor()
return author;
public void setAccinfo(List accinfo)
this.accinfo = accinfo;
public List getAccinfo()
return accinfo;
* To change this template, choose Tools | Templates
* and open the template in the editor.
package hibernate.example;
import hibernate.example.Acctinfo;
import hibernate.example.Catalog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class CatalogClient
Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
public static void main(String str[])
CatalogClient clc = new CatalogClient();
//clc.saveData();
//clc.deleteData();
//clc.showData();
clc.updateData();
public void showData()
try
session =sessionFactory.openSession();
String SQL_QUERY ="select id, journal, publisher, edition, title, author from catalog";
// String SQL_QUERY ="select c.ID, c.JOURNAL, c.PUBLISHER, c.EDITION, c.TITLE, c.AUTHOR, a.ACCOUNT, a.PASSWORD,a.BALANCE from catalog c, ACCTINFO a where c.ID = a.ID";
SQLQuery query = session.createSQLQuery(SQL_QUERY);
System.out.println("*** query : *** "+ query);
//for(ListIterator it=query.list().listIterator();it.hasNext();)
for (ListIterator lit = query.list().listIterator(); lit.hasNext();)
Object[] row = (Object[]) lit.next();
/*System.out.println("ID: " + row[0]);
System.out.println("Title: " + row[1]);
System.out.println("Author: " + row[2]);
System.out.println("Isbn: " + row[3]);
System.out.println("Pages: " + row[4]);
System.out.println("Copyright: " + row[5]);
System.out.println("Cost: " + row[6]);
System.out.println("******NEXT****************");
Object[] row = (Object[]) it.next();*/
System.out.println("ID: " + row[0]);
System.out.println("JOURNAL: " + row[1]);
System.out.println("PUBLISHER: " + row[2]);
System.out.println("EDITION: " + row[3]);
System.out.println("TITLE: " + row[4]);
System.out.println("AUTHOR: " + row[5]);
System.out.println("acc: " + row[6]);
System.out.println("pass: " + row[7]);
System.out.println("bal: " + row[8]);
System.out.println("***************************");
session.close();
catch(Exception e)
System.out.println(e.getMessage());
public void saveData()
session =sessionFactory.openSession();
Transaction transaction = null;
transaction = session.beginTransaction();
Catalog catalog = setBean();
//System.out.println("before save");
session.save(catalog);
//System.out.println("after save");
transaction.commit();
session.flush();
session.close();
public void updateData()
session =sessionFactory.openSession();
Catalog catalog = new Catalog();
catalog.setId(2);
catalog.setAuthor("manoj");
catalog.setJournal("java");
catalog.setEdition("1st");
catalog.setPublisher("indiabulls");
catalog.setTitle("java Servlet");
session.update(catalog);
session.flush();
session.close();
public void deleteData()
session =sessionFactory.openSession();
Catalog catalog = new Catalog();
catalog.setId(3);
session.delete(catalog);
session.flush();
session.close();
public static Catalog setBean()
Acctinfo accinfo = new Acctinfo();
accinfo.setAccount("MANOJ1");
accinfo.setPassword("orbis");
accinfo.setBalance("1000");
List list = new ArrayList();
list.add(accinfo);
Catalog catalog = new Catalog();
catalog.setJournal("india");
catalog.setPublisher("indiabulls");
catalog.setEdition("ist");
catalog.setTitle("orbis");
catalog.setAuthor("manoj");
catalog.setAccinfo(list);
return catalog;
//********************CFG FILE IS ******************
<?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 name="session">
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@172.16.31.25:1521:BOMBAY</property>
<property name="hibernate.connection.username">mumbai</property>
<property name="hibernate.connection.password">mumbai123</property>
<!-- Set AutoCommit to true -->
<property name="connection.autocommit">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Mapping files -->
<mapping resource="Catalog.hbm.xml"/>
</session-factory>
</hibernate-configuration>
**********************error i m facing is :************************
0 [main] WARN net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/d.poonam/Desktop/hibernate/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
1188 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory - Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:247)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
at hibernate.example.CatalogClient.<init>(CatalogClient.java:24)
at hibernate.example.CatalogClient.main(CatalogClient.java:27)
please help me out....
thanks in advance..
if u know how to connect two tables plz let me know..
its urgent....I made this work with MySQL. Adapt to your situation as needed. - %
package hibernate.model;
import hibernate.util.HibernateUtils;
import hibernate.model.Catalog;
import hibernate.model.Account;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import hibernate.util.HibernateUtils;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
public class CatalogTest
private static final Log LOGGER = LogFactory.getLog(CatalogTest.class);
public static void main(String[] args)
Session session = null;
try
session = HibernateUtils.getSessionFactory().getCurrentSession();
session.beginTransaction();
int rowsBefore = HibernateUtils.getRowCount(session, Catalog.class);
assertEquals("should not have any Catalogs", rowsBefore, 0);
Catalog catalog = new Catalog("test title");
catalog.addAccount(new Account(100));
catalog.addAccount(new Account(200));
Long id = (Long) session.save(catalog);
assertNotNull("generated id should not be null", id);
LOGGER.info("returned id: " + id);
session.getTransaction().commit();
LOGGER.debug("transaction committed");
catch (Exception e)
LOGGER.error(e);
session.getTransaction().rollback();
package hibernate.model;
import java.io.Serializable;
import java.text.NumberFormat;
public class Account implements Serializable
private Long id;
private int balance;
public Account()
this(null, 0);
public Account(int balance)
this(null, balance);
public Account(Long id, int balance)
this.id = id;
this.balance = balance;
public Long getId()
return id;
private void setId(Long id)
this.id = id;
public int getBalance()
return balance;
private void setBalance(int balance)
this.balance = balance;
public boolean equals(Object o)
if (this == o)
return true;
if (!(o instanceof Account))
return false;
Account account = (Account) o;
return !(id != null ? !id.equals(account.id) : account.id != null);
public int hashCode()
int result;
result = (id != null ? id.hashCode() : 0);
result = 31 * result + balance;
return result;
public String toString()
return new StringBuilder().append("Account{").append("id=").append(id).append(", balance=").append(NumberFormat.getCurrencyInstance().format(balance)).append('}').toString();
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate.model" default-access="field" default-lazy="true">
<class name="Account" table="accounts">
<id name="id" column="account_id">
<generator class="native"/>
</id>
<property name="balance" column="balance"/>
</class>
</hibernate-mapping>
package hibernate.model;
import java.io.Serializable;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
public class Catalog implements Serializable
private Long id;
private String title;
private Set<Account> accounts;
public Catalog()
this(null, "", Collections.EMPTY_SET);
public Catalog(String title)
this(null, title, Collections.EMPTY_SET);
public Catalog(Long id, String title, Set<Account> accounts)
this.id = id;
this.title = title;
this.accounts = new HashSet<Account>(accounts);
public Long getId()
return id;
private void setId(Long id)
this.id = id;
public String getTitle()
return title;
private void setTitle(String title)
this.title = title;
public Set<Account> getAccounts()
return accounts;
private void setAccounts(Set<Account> accounts)
this.accounts = accounts;
public void addAccount(Account account)
this.getAccounts().add(account);
public void removeAccount(Account account)
this.getAccounts().remove(account);
public boolean equals(Object o)
if (this == o)
return true;
if (!(o instanceof Catalog))
return false;
Catalog catalog = (Catalog) o;
return !(id != null ? !id.equals(catalog.id) : catalog.id != null);
public int hashCode()
return (id != null ? id.hashCode() : 0);
public String toString()
return new StringBuilder().append("Catalog{").append("id=").append(id).append(", title='").append(title).append('\'').append(", accounts=").append(accounts).append('}').toString();
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate.model" default-access="field" default-lazy="true">
<class name="Catalog" table="catalogs">
<id name="id" column="catalog_id">
<generator class="native"/>
</id>
<property name="title" column="title"/>
<set name="accounts" cascade="all">
<key column="catalog_id"/>
<one-to-many class="hibernate.model.Account"/>
</set>
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate?autoReconnect=true</property>
<property name="connection.username">hibernate</property>
<property name="connection.password">hibernate</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="show_sql">true</property>
<property name="generate_statistics">true</property>
<property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_minimal_puts">false</property>
<property name="cache.use_query_cache">false</property>
<property name="order_updates">false</property>
<property name="hbm2ddl.auto">create-drop</property>
<property name="current_session_context_class">thread</property>
<mapping resource="hibernate/persistence/hibernate/Account.hbm.xml"/>
<mapping resource="hibernate/persistence/hibernate/Catalog.hbm.xml"/>
</session-factory>
</hibernate-configuration> -
Trouble connecting to MySQL database with Hibernate
I'm using red hat studio pro. I created an hibernate.cfg.xml file with
the hibernate tools.
Code:
<?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>
<property name="hibernate.connection.driver_jar">mysql-connector-
java-5.0.6-bin.jar</property>
<property
name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</
property>
<property name="hibernate.connection.password"> </property>
<property name="hibernate.connection.url">jdbc:mysql://
localhost/eshop</property>
<property name="hibernate.connection.username">user</property>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</
property>
</session-factory>
</hibernate-configuration>
Reverse Engineering was no problem, it found the database, could read
the tables and create the java classes.
Now I tried to open a simple connection to the database and that
doesn*t work. I always get a "no suitable driver found" error.
Code:
Configuration config = new Configuration()
.setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQLInnoDBDialect")
.setProperty("hibernate.connection.driver_class",
"org.gjt.mm.mysql.Driver")
.setProperty("hibernate.connection.driver_jar", "mysql-connector-
java-5.0.6-bin.jar")
.setProperty("hibernate.connection.password", " ")
.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:
3306/eshop")
.setProperty("hibernate.connection.username", "user")
.addClass(Adressen.class);
config.configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
System.out.println("works");
} catch (Exception e) {
if (tx != null) {
tx.rollback();
System.out.println("error - rollback");
} finally {
session.close();
sessionFactory.close();
The errors I'm getting are:
Code:
23:41:05,187 INFO [Environment] Hibernate 3.2.4.sp1
23:41:05,187 INFO [Environment] loaded properties from resource
hibernate.properties: {hibernate.co
nnection.username=user, hibernate.connection.password=****,
hibernate.dialect=org.hibernate.dialect.
MySQLInnoDBDialect, hibernate.connection.url=jdbc:mysql://localhost:
3306/eshop, hibernate.bytecode.u
se_reflection_optimizer=false,
hibernate.connection.driver_class=com.mysql.jdbc.Driver}
23:41:05,187 INFO [Environment] Bytecode provider name : javassist
23:41:05,203 INFO [Environment] using JDK 1.4 java.sql.Timestamp
handling
23:41:05,312 INFO [Configuration] Reading mappings from resource:
hibernateGenerated/Adressen.hbm.x
ml
23:41:05,312 INFO [Configuration] Reading mappings from resource:
hibernateGenerated/Adressen.hbm.x
ml
23:41:05,515 INFO [HbmBinder] Mapping class:
hibernateGenerated.Adressen -> Adressen
23:41:05,531 INFO [Configuration] configuring from resource: /
hibernate.cfg.xml
23:41:05,531 INFO [Configuration] Configuration resource: /
hibernate.cfg.xml
23:41:05,546 INFO [Configuration] Configured SessionFactory: null
23:41:05,656 INFO [DriverManagerConnectionProvider] Using Hibernate
built-in connection pool (not f
or production use!)
23:41:05,656 INFO [DriverManagerConnectionProvider] Hibernate
connection pool size: 20
23:41:05,656 INFO [DriverManagerConnectionProvider] autocommit mode:
false
23:41:05,656 INFO [DriverManagerConnectionProvider] using driver:
org.gjt.mm.mysql.Driver at URL: j
dbc:mysql://localhost/eshop
23:41:05,656 INFO [DriverManagerConnectionProvider] connection
properties: {driver_jar=mysql-connec
tor-java-5.0.6-bin.jar, user=user, password= }
23:41:05,656 WARN [SettingsFactory] Could not obtain connection
metadata
java.sql.SQLException: No suitable driver found for jdbc:mysql://
localhost/eshop
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionPr
ovider.java:110)
at
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:
2009)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:
1292)
at sample.RegisterAciton.writeInDatabase(RegisterAciton.java:147)
at sample.RegisterAciton.execute(RegisterAciton.java:246)
at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:
484)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:
525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:
96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
230)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:
179)
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:
84)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
104)
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:
157)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
241)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447)
at java.lang.Thread.run(Unknown Source)
23:41:06,046 INFO [Dialect] Using dialect:
org.hibernate.dialect.MySQLInnoDBDialect
23:41:06,046 INFO [TransactionFactoryFactory] Using default
transaction strategy (direct JDBC trans
actions)
23:41:06,046 INFO [TransactionManagerLookupFactory] No
TransactionManagerLookup configured (in JTA
environment, use of read-write or transactional second-level cache is
not recommended)
23:41:06,046 INFO [SettingsFactory] Automatic flush during
beforeCompletion(): disabled
23:41:06,046 INFO [SettingsFactory] Automatic session close at end of
transaction: disabled
23:41:06,046 INFO [SettingsFactory] Scrollable result sets: disabled
23:41:06,062 INFO [SettingsFactory] JDBC3 getGeneratedKeys():
disabled
23:41:06,062 INFO [SettingsFactory] Connection release mode: auto
23:41:06,062 INFO [SettingsFactory] Maximum outer join fetch depth: 2
23:41:06,062 INFO [SettingsFactory] Default batch fetch size: 1
23:41:06,062 INFO [SettingsFactory] Generate SQL with comments:
disabled
23:41:06,062 INFO [SettingsFactory] Order SQL updates by primary key:
disabled
23:41:06,062 INFO [SettingsFactory] Order SQL inserts for batching:
disabled
23:41:06,062 INFO [SettingsFactory] Query translator:
org.hibernate.hql.ast.ASTQueryTranslatorFacto
ry
23:41:06,062 INFO [ASTQueryTranslatorFactory] Using
ASTQueryTranslatorFactory
23:41:06,062 INFO [SettingsFactory] Query language substitutions: {}
23:41:06,062 INFO [SettingsFactory] JPA-QL strict compliance:
disabled
23:41:06,062 INFO [SettingsFactory] Second-level cache: enabled
23:41:06,062 INFO [SettingsFactory] Query cache: disabled
23:41:06,062 INFO [SettingsFactory] Cache provider:
org.hibernate.cache.NoCacheProvider
23:41:06,062 INFO [SettingsFactory] Optimize cache for minimal puts:
disabled
23:41:06,062 INFO [SettingsFactory] Structured second-level cache
entries: disabled
23:41:06,078 INFO [SettingsFactory] Statistics: disabled
23:41:06,078 INFO [SettingsFactory] Deleted entity synthetic
identifier rollback: disabled
23:41:06,078 INFO [SettingsFactory] Default entity-mode: pojo
23:41:06,078 INFO [SettingsFactory] Named query checking : enabled
23:41:06,125 INFO [SessionFactoryImpl] building session factory
23:41:06,437 INFO [SessionFactoryObjectFactory] Not binding factory
to JNDI, no JNDI name configure
d
23:41:06,515 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState:
08001
23:41:06,515 ERROR [JDBCExceptionReporter] No suitable driver found
for jdbc:mysql://localhost/eshop
23:41:06,515 INFO [SessionFactoryImpl] closing
23:41:06,515 INFO [DriverManagerConnectionProvider] cleaning up
connection pool: jdbc:mysql://local
host/eshop
Can anybody tell me, what I'm doing wrong?ClassNotFoundException means the driver isn't loaded. "No suitable driver" usually tells me that the syntax in the connection URL is incorrect for some reason.
Make sure you have an up to date driver JAR:
http://www.mysql.com/products/connector/j/
The driver class name should be com.mysql.jdbc.Driver
% -
Help me About Hibernate Sample
i tried to make a sample under the book <hibernate-reference>, but the following error message appeared:
==========================
17:30:42,265 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext
17:30:42,312 INFO SessionFactoryImpl:379 - Checking 0 named queries
StandardWrapperValve[personservlet]: Servlet.service() for servlet personservlet threw exception
java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:116)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:554)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:56)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:137)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49)
at org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:24)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079)
at testhibernate.PersonServlet.doGet(PersonServlet.java:37)
at testhibernate.PersonServlet.doPost(PersonServlet.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
==========================
HELP MERemove
hibernate.connection.usernameand
hibernate.connection.passwordfrom your hibernate.cfg.xml
I got the same problem and removing those property entries should fix the problem.
I dont know why the error occures. -
Spring-Webflow Authentication and Hibernate
Does anyone have experience authenticating against Oracle using Spring 2.5, Spring-Webflow, Hibernate 3.3? Then using the authenticated credentials to create a proxy authenticated connection for hibernate?
Does anyone have experience authenticating against Oracle using Spring 2.5, Spring-Webflow, Hibernate 3.3? Then using the authenticated credentials to create a proxy authenticated connection for hibernate?
-
Hello everyone, sorry someone knows how can I use hibernate on the layer model, and ADF in the presentation layer?
I have made my connection to hibernate and I have also designed my page with ADF, and to unite both layers I created a "Data Control" but they do not work for me. I get the following error:
java.lang.OutOfMemoryError: PermGen space
sun.misc.Unsafe.defineClass at (Native Method)
at sun.reflect.ClassDefiner.defineClass (ClassDefiner.java: 45)
sun.reflect.MethodAccessorGenerator at $ 1.run (MethodAccessorGenerator.java: 381)
at java.security.AccessController.doPrivileged (Native Method)
at sun.reflect.MethodAccessorGenerator.generate (MethodAccessorGenerator.java: 377)
Truncated. see log file for complete Stacktrace
I think the error is when direcceciono in your hibernate file "hibernate.cfg.xml" because I write everything from what direction the unit c. I do this because when I write I do not routed to the directory where JDeveloper is installed.
Agradesco them in advance for your kind responses.Hi Jhon, thanks for your help, and I get no error.
But when is not output any data in the table.
Here I show you the code:
group.jspx_
<af:panelCollection>
<f:facet name="menus"/>
<f:facet name="toolbar"/>
<f:facet name="statusbar"/>
<af:table value="#{bindings.grupos.collectionModel}"
var="row" rows="#{bindings.grupos.rangeSize}"
emptyText="#{bindings.grupos.viewable ? 'No rows yet.' : 'Access Denied.'}"
fetchSize="#{bindings.grupos.rangeSize}"
selectedRowKeys="#{bindings.grupos.collectionModel.selectedRow}"
selectionListener="#{bindings.grupos.collectionModel.makeCurrent}"
rowSelection="single" columnSelection="single"
editingMode="clickToEdit">
<af:column sortProperty="id" sortable="true"
headerText="#{bindings.grupos.hints.id.label}">
<af:inputText value="#{row.bindings.id.inputValue}"
label="#{bindings.grupos.hints.id.label}"
required="#{bindings.grupos.hints.id.mandatory}"
columns="#{bindings.grupos.hints.id.displayWidth}"
maximumLength="#{bindings.grupos.hints.id.precision}"
shortDesc="#{bindings.grupos.hints.id.tooltip}">
<f:validator binding="#{row.bindings.id.validator}"/>
</af:inputText>
</af:column>
<af:column sortProperty="descripcion" sortable="true"
headerText="#{bindings.grupos.hints.descripcion.label}">
<af:inputText value="#{row.bindings.descripcion.inputValue}"
label="#{bindings.grupos.hints.descripcion.label}"
required="#{bindings.grupos.hints.descripcion.mandatory}"
columns="#{bindings.grupos.hints.descripcion.displayWidth}"
maximumLength="#{bindings.grupos.hints.descripcion.precision}"
shortDesc="#{bindings.grupos.hints.descripcion.tooltip}">
<f:validator binding="#{row.bindings.descripcion.validator}"/>
</af:inputText>
</af:column>
<af:column sortProperty="estado" sortable="true"
headerText="#{bindings.grupos.hints.estado.label}">
<af:inputText value="#{row.bindings.estado.inputValue}"
label="#{bindings.grupos.hints.estado.label}"
required="#{bindings.grupos.hints.estado.mandatory}"
columns="#{bindings.grupos.hints.estado.displayWidth}"
maximumLength="#{bindings.grupos.hints.estado.precision}"
shortDesc="#{bindings.grupos.hints.estado.tooltip}">
<f:validator binding="#{row.bindings.estado.validator}"/>
</af:inputText>
</af:column>
<af:column sortProperty="inserted" sortable="true"
headerText="#{bindings.grupos.hints.inserted.label}">
<af:inputDate value="#{row.bindings.inserted.inputValue}"
label="#{bindings.grupos.hints.inserted.label}"
required="#{bindings.grupos.hints.inserted.mandatory}"
shortDesc="#{bindings.grupos.hints.inserted.tooltip}">
<f:validator binding="#{row.bindings.inserted.validator}"/>
<af:convertDateTime pattern="#{bindings.grupos.hints.inserted.format}"/>
</af:inputDate>
</af:column>
</af:table>
</af:panelCollection>
ServiceGroup.java_
public class ServicioGrupo {
Collection<Grupo> grupos = new ArrayList<Grupo>();
public ServicioGrupo() {
try {
catch (Exception e)
{ e.printStackTrace(); }
public void addGrupo( String gdescription ) {
Grupo group = new Grupo(gdescription);
try {
DaoMgr.save(group);
} catch (Exception e) {
e.printStackTrace();
public void addOrUpdateGrupo ( int id, String gdescription, boolean estado ) {
Grupo group = new Grupo(id, gdescription, estado);
try {
DaoMgr.saveOrUpdate(group);
} catch (Exception e) {
e.printStackTrace();
public void deleteGrupo( int id ) {
Grupo grupo = new Grupo();
grupo.setId(id);
try {
} catch (Exception e) {
e.printStackTrace();
public void setGroups( Collection<Grupo> newgrupos ) {
this.grupos = newgrupos;
public Collection<Grupo> getGrupos() {
try {
Grupo grupo = new Grupo();
String sql = "Select * from grupo;";
grupos = DaoMgr.load(sql, grupo);
System.out.println(grupos.size());
} catch (Exception e) {
e.printStackTrace();
return grupos;
and this method connection Hibernate
private HibernateUtil()
sessionFactory = null;
File conf = new File((new StringBuilder("conf")).append(File.separator).append("hibernate.cfg.xml").toString());
if(!conf.exists())
conf = new File((new StringBuilder("..")).append(File.separator).append("conf").append(File.separator).append("hibernate.cfg.xml").toString());
sessionFactory = (new Configuration()).configure(conf).buildSessionFactory();
if (sessionFactory == null)
System.out.println("nulo");
thanks in advance for your help -
Problem with connect to sql server ..
I have problem with connect to sql server2005
i use jpa(hibernate) and jsf
javax.servlet.ServletException: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
root cause
javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
root cause
javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1371)
org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
servlet.PrzychodniaBean.dodaj(PrzychodniaBean.java:30)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:262)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
root cause
org.hibernate.exception.JDBCConnectionException: Could not open connection
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1263)
org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:57)
servlet.PrzychodniaBean.dodaj(PrzychodniaBean.java:30)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:262)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
root cause
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost;databaseName=MIS
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173)
org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:276)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1263)
org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:57)
servlet.PrzychodniaBean.dodaj(PrzychodniaBean.java:30)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:262)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
note The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.
persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="PrzychodnieLekarskiePU" transaction-type="RESOURCE_LOCAL">
<class>model.Przychodznia</class>
<properties>
<property name="hibernate.connection.username" value="a"/>
<property name="hibernate.connection.password" value="a"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://localhost;databaseName=MIS"/>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost;databaseName=MIS"/>
<property name="javax.persistence.jdbc.user" value="a"/>
<property name="javax.persistence.jdbc.password" value="a"/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
</properties>
</persistence-unit>
</persistence>
Edited by: 985713 on 2013-02-02 07:12
Edited by: 985713 on 2013-02-02 07:37it works ok : I don't known where is error in jpa .. ?
public class MyConnection {
public static Connection getConnection () throws SQLException{
String url = "jdbc:sqlserver://ABADDON1;databaseName=MIS";
String user = "a";
String pass = "a";
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
Connection conn = DriverManager.getConnection(
url,user,pass);
System.out.println("OK");;
return conn;
try {
conn = MyConnection.getConnection();
} catch (SQLException ex) {
System.out.println("Error: " + ex.getErrorCode()
+ ex.getMessage());
} -
I want to use hibernate with the tomcat
I want to use hibernate with the tomcat server can it be possible and if yes then what is the stepwise way.
Infact I know the java JSF but want to command on Hibernate plz help me.
I'll be thankful to you.To be honest, I wouldn't even know where to start. Do you know what Hibernate does and how it works? Do you know how Tomcat works? All you'd need to do to combine those two would be to let Tomcat provide the DB connections for Hibernate, I suppose. Neither of those products are a topic of this board though.
-
Losing connection to db with many users
Hi all,
I'm using tomcat 6 + mysql + c3p0 connection pools + hibernate.
If i test my web application with Apache JMeter simulating 100 users (threads?!) in a page, after 5-30 seconds i will lose the connection to db.
If I redeploy the application it work again... In the tomcat manager I see 15'000/18'000 sessions :S
Please help me and sorry for my bad englishPlease have a bit more patience. I can't imagine that this topic was already out of the sight of the active topic listing after 5 hours.
-
手把手配置Hibernate环境(JBuilderX版)
今天花了一些时间写了一篇文章<<手把手配置Hibernate环境>>,里面包括一整套基本的Hibernate开发流程,从最简单的开始,我觉得这篇文章对初学者很有用,所以好东西当然少不了大家的,贴上来和大家一起分享,呵呵.
手把手配置Hibernate环境(JBuilderX版)
作者:bluesky35(蓝天)
开发环境: Windows2000 + JBuilderX + Hibernate2.1.6 + Oracle9i
1.安装JBuilderX和Oracle9i,并使用以下信息配置Oracle
用户名:system
密码:admin
服务:cpdb
2.先去http://prodownloads.sourceforge.net/hibernate/下载Hibernate API的包hibernate-2.1.6.zip
3.在JBuilder中选择Project菜单中的Project Properties,在Require Library中加入Hibernate所有的API包,还要加入Oracle目录ORANT\jdbc\lib\classes12.zip
4.然后将截压缩后的hibernate-2.1\etc\hibernate.properties拷贝到本地project的classes目录下然后做以下变化:
①注释默认的数据库连接,将
## HypersonicSQL
hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class org.hsqldb.jdbcDriver
hibernate.connection.username sa
hibernate.connection.password
hibernate.connection.url jdbc:hsqldb:hsql://localhost
hibernate.connection.url jdbc:hsqldb:test
hibernate.connection.url jdbc:hsqldb:.
改为
## HypersonicSQL
#hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
#hibernate.connection.driver_class org.hsqldb.jdbcDriver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:hsqldb:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test
#hibernate.connection.url jdbc:hsqldb:.
然后修改Oracle的连接,将
## Oracle
#hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
#hibernate.dialect net.sf.hibernate.dialect.OracleDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:test
改为
## Oracle
hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
hibernate.dialect net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
hibernate.connection.username system
hibernate.connection.password admin
hibernate.connection.url jdbc:oracle:thin:@172.28.122.49:1521:cpdb
注意:@172.28.122.49为Oracle服务器的ip地址,1521为端口号
5.在project下建立package person,在package下建立四个class,分别为:
①PersonModel.java
package person;
import java.io.Serializable;
public class PersonModel implements Serializable {
private Long id;
private String name;
private String address;
public Long getId() {
return id;
public void setId(Long id) {
this.id = id;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setAddress(String address) {
this.address = address;
public String getAddress() {
return address;
②TestPersonModel1.java
package person;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
public class TestPersonModel1 {
private static SessionFactory sessionFactory;
public static void main(String[] args) throws Exception{
System.out.println("start");
Configuration conf= new Configuration().addClass(PersonModel.class);
SchemaExport dbExport=new SchemaExport(conf);
dbExport.setOutputFile("sql_out_lib\\sql.txt");
dbExport.create(true, true);
③TestPersonModel2.java
package person;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
public class TestPersonModel2 {
private static SessionFactory sessionFactory;
public static void main(String[] args) throws Exception{
Configuration conf= new Configuration().addClass(PersonModel.class);
//在表中插入第一条数据
sessionFactory = conf.buildSessionFactory();
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
PersonModel p1=new PersonModel();
p1.setName("zhaol");
p1.setAddress("shanghai");
//持久化
s.save(p1);
//数据库中已有记录
t.commit();
s.close();
④TestPersonModel3.java
package person;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Query;
public class TestPersonModel3 {
private static SessionFactory sessionFactory;
public static void main(String[] args) throws Exception{
Configuration conf= new Configuration().addClass(PersonModel.class);
sessionFactory = conf.buildSessionFactory();
Session s = sessionFactory.openSession();
PersonModel p = new PersonModel();
Query q = s.createQuery("from PersonModel as p where p.id=1");
p = (PersonModel) q.list().get(0);
System.out.println(p.getName());
s.close();
其中PersonModel.java是对应数据库中字段的存储结构,TestPersonModel1.java是测试自动创建表和字段,TestPersonModel2.java是测试在表中插入记录,TestPersonModel3.java是测试从表中取得记录.
6.编译所有的java文件
7.好了,到最后一步了,也是最关键的一步,我们已经定义了数据库连接(hibernate.properties)
创建了字段的存储结构(PersonModel.java),也写好了操作数据库的代码(TestPersonModel1.java~TestPersonModel3.java),接下来要做的是定义数据库中表的配置文件,因为我们的字段的存储结构文件是PersonModel.java,所以创建PersonModel.hbm.xml(注意:表的配置文件名是由[字段的存储结构文件名+.hbm.xml]构成,创建位置为project的class\person目录下(注意:数据库定义文件hibernate.properties是放在class目录下的,而表的配置文件要放在相对应的包下,我们这里的包名是person,所以就放在class\person下)
PersonModel.hbm.xml的内容如下:
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="person.PersonModel"
table="zl">
<id name="id" type="long">
<generator class="sequence">
<param name="sequence">ZL_ID_SEQ</param>
</generator>
</id>
<property name="name"/>
<property name="address"/>
</class>
</hibernate-mapping>
表名为zl,里面有两个字段(name和address,对应person.PersonModel),id是一个sequence.
9.好了,配置完成,接下来运行一下吧,先运行TestPersonModel1.class,让hibernate为我们自动建立一张名为zl(内有字段name和address)的表
怎么样?表是不是已经建好了,呵呵.
接下来运行TestPersonModel2.class,让hibernate再为我们插入一条记录
hibernate环境的配置就讲到这里,如有疑问可以和我联系:),我的QQ是81806701.
大家注意:完整的带图的文章我已经发表在blog里,地址是:
http://blog.csdn.net/bluesky35/archive/2004/11/18/185689.aspx为什么我的出现这样的错
D:\JBuilderX\jdk1.4\bin\javaw -classpath "D:\quickstart\classes;E:\hibernate-3.0\hibernate-3.0\lib\ant-1.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\ant-antlr-1.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\ant-junit-1.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\ant-launcher-1.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\antlr-2.7.5H3.jar;E:\hibernate-3.0\hibernate-3.0\lib\ant-swing-1.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\asm.jar;E:\hibernate-3.0\hibernate-3.0\lib\asm-attrs.jar;E:\hibernate-3.0\hibernate-3.0\lib\c3p0-0.8.5.jar;E:\hibernate-3.0\hibernate-3.0\lib\cglib-2.1.jar;E:\hibernate-3.0\hibernate-3.0\lib\cleanimports.jar;E:\hibernate-3.0\hibernate-3.0\lib\commons-collections-2.1.1.jar;E:\hibernate-3.0\hibernate-3.0\lib\commons-logging-1.0.4.jar;E:\hibernate-3.0\hibernate-3.0\lib\concurrent-1.3.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\connector.jar;E:\hibernate-3.0\hibernate-3.0\lib\dom4j-1.5.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\ehcache-1.1.jar;E:\hibernate-3.0\hibernate-3.0\lib\jaas.jar;E:\hibernate-3.0\hibernate-3.0\lib\jacc-1_0-fr.jar;E:\hibernate-3.0\hibernate-3.0\lib\jaxen-1.1-beta-4.jar;E:\hibernate-3.0\hibernate-3.0\lib\jboss-cache.jar;E:\hibernate-3.0\hibernate-3.0\lib\jboss-common.jar;E:\hibernate-3.0\hibernate-3.0\lib\jboss-jmx.jar;E:\hibernate-3.0\hibernate-3.0\lib\jboss-system.jar;E:\hibernate-3.0\hibernate-3.0\lib\jdbc2_0-stdext.jar;E:\hibernate-3.0\hibernate-3.0\lib\jgroups-2.2.7.jar;E:\hibernate-3.0\hibernate-3.0\lib\jta.jar;E:\hibernate-3.0\hibernate-3.0\lib\junit-3.8.1.jar;E:\hibernate-3.0\hibernate-3.0\lib\log4j-1.2.9.jar;E:\hibernate-3.0\hibernate-3.0\lib\oscache-2.1.jar;E:\hibernate-3.0\hibernate-3.0\lib\proxool-0.8.3.jar;E:\hibernate-3.0\hibernate-3.0\lib\swarmcache-1.0rc2.jar;E:\hibernate-3.0\hibernate-3.0\lib\versioncheck.jar;E:\hibernate-3.0\hibernate-3.0\lib\xerces-2.6.2.jar;E:\hibernate-3.0\hibernate-3.0\lib\xml-apis.jar;E:\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga\mysql.jar;E:\hibernate-3.0\hibernate-3.0\hibernate3.jar;D:\JBuilderX\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilderX\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;D:\JBuilderX\jdk1.4\jre\javaws\javaws.jar;D:\JBuilderX\jdk1.4\jre\lib\charsets.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\dnsns.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\ldapsec.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\localedata.jar;D:\JBuilderX\jdk1.4\jre\lib\ext\sunjce_provider.jar;D:\JBuilderX\jdk1.4\jre\lib\im\indicim.jar;D:\JBuilderX\jdk1.4\jre\lib\im\thaiim.jar;D:\JBuilderX\jdk1.4\jre\lib\jce.jar;D:\JBuilderX\jdk1.4\jre\lib\jsse.jar;D:\JBuilderX\jdk1.4\jre\lib\plugin.jar;D:\JBuilderX\jdk1.4\jre\lib\rt.jar;D:\JBuilderX\jdk1.4\jre\lib\sunrsasign.jar;D:\JBuilderX\jdk1.4\lib\dt.jar;D:\JBuilderX\jdk1.4\lib\htmlconverter.jar;D:\JBuilderX\jdk1.4\lib\tools.jar" hibernate.TestPersonModel1
java.lang.ExceptionInInitializerError
at hibernate.TestPersonModel1.main(TestPersonModel1.java:11)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@f62373 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@f62373 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category))start
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:110)
... 1 more
Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@f62373 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:413)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
at java.lang.Class.getConstructor0(Class.java:1922)
at java.lang.Class.getConstructor(Class.java:1019)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:410)
... 6 more
Exception in thread "main"
-
Insert then update on same row in bean Transaction leads to deadlock
<b>Setup Details</b>
Hibernate version: 3.1.2
EJB version: 2.0
Name and version of the database : MS SQL Server 2000
Datasource implmentation class being used : com.sap.nwmss.jdbcx.sqlserver.SQLServerDataSource
We are using SAP NetWeaver Application Server 6.0 and Hibernate 3.1.2 in our application. We have StalessSessionBeans which use Hibernate to interact with the database. We are running into a situation where the application goes into a hang state when the following flow is bein executed:
//transaction attribute = "Required"
beanMethod() {
myObj = new MyObj();
myObj.setSomeValue();
session = SessionFactory.openSession();
//id is auto generated by database
id = session.insert(myObj);
//retrieve the recently inserted obj
myUpdatedObj = session.load(id);
//modify the myUpdatedObj
myUpdatedObj.modifySomeValue();
//update using hibernate session
session.update(myUpdatedObj);
//return from method
Here's the flow:
1) In a CMT stateless session bean, there's a method which has transaction atrribute as "Required"
2) This method creates a new object and inserts it
3) Then loads this saved object and modifies some values in it
4) Then invokes the update method on the session to update this modified object in the database.
Note: We have enabled auto flush on transaction in the hibernate configuration file.
And here's what we are observing:
- The insert obtains a lock on the row as part of the transaction
- When the update is called on the same row as part of the auto flush, the update never completes. The update statement is unable to obtain a lock on the same row.
Here is some additional info:
- We have set :
session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
hibernate.cfg.xml:
<?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>
<property name="hibernate.jndi.class">
com.sap.engine.services.jndi.InitialContextFactoryImpl
</property>
<property name="hibernate.session_factory_name">
HibernateSessionFactory
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.connection.datasource">jdbc/SQLPool1</property>
<property name="hibernate.connection.pool_size">25</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.isolation">1</property>
<property name="hibernate.prepare_sql">true</property>
<property name="hibernate.statement_cache.size">10000</property>
<!--property name="hibernate.jdbc.use_scrollable_resultset">true</property-->
<property name="transaction.manager_lookup_class">
com.tdemand.server.util.hibernate.SAPWebASTransactionManagerLookup
</property>
<property name="hibernate.jdbc.use_get_generated_keys">
false
</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.jdbc.batch_size">1000</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
</session-factory>
</hibernate-configuration>
Any clue why the update query is having problem in completing, even though update and insert are being called from the same bean method as part of a transaction?
Here's the log:
2006-11-01 22:10:00,310 INFO [com.tdemand.server.planning.ejbs.ForecastPlanningSessionBean] - Starting save
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement"insert into aa values ('1', '2', '3','4','5',6,7);
if sql%rowcount <> 1 then
RAISE_APPLICATION_ERROR(-20999, 'insert aa err');
END IF;
/* skip some code
update aa set dept_code = '3' where fee_month = '1';
if sql%rowcount <> 1 then"
Is Dept_Code the 2nd Column in the table aa. If so then
why update the table ?
Why not Insert Into aa Values ('1', '3', '3' ......);
Have a look at the sample script which is doing Insert followed by updating the same table using the ROWID.
Test Db>desc temp;
Name Null? Type
COL1 VARCHAR2(10)
COL2 VARCHAR2(10)
COL3 VARCHAR2(10)
COL4 VARCHAR2(10)
ID NUMBER
Test Db>select * from temp;
no rows selected
Test Db>get t1
1 Set ServerOutput On Size 999999;
2 Declare
3 lRow Varchar2(50);
4 Begin
5 Insert Into Temp (Col1, Col2, Col3, Col4, Id)
6 Values ('A', 'B', 'C', 'D', 100)
7 RETURNING RowId Into lRow;
8 Dbms_Output.Put_Line ('RowId = ' || lRow);
9 Update Temp Set col2 = 'B1'
10 Where RowId = lRow;
11 Dbms_Output.Put_Line ('Row Updated');
12* End;
13 /
Test Db>@t1
RowId = AAAKsqAAJAAAEbsAAG
Row Updated
PL/SQL procedure successfully completed.
Test Db>select * from temp;
COL1 COL2 COL3 COL4 ID
A B1 C D 100
-- Shailender Mehta -- -
Hi !!!
I was working ok, with hibernate and mysql but yesterday I try to install the new mysql version (4.1.10) and receive the following error when I try to connect
Initializing Hibernate
INFO - Hibernate 2.1.6
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: com/tutorial/hibernate/core/News.hbm.xml
INFO - Mapping class: com.tutorial.hibernate.core.News -> news
INFO - Configured SessionFactory: null
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.MySQLDialect
INFO - Maximim outer join fetch depth: 2
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 20
INFO - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/unnobanews
INFO - connection properties: {user=news, password=news}
INFO - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
WARN - Could not obtain connection metadata
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at org.gjt.mm.mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm.mysql.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
Somewhere I red that was necessary to update the jdbc driver, so I updated it from version nro 2 to version nro 3.1.7 but still the error
Phpmyadmin works ok and mysql control center can connect ok too.
But when I try a telnet localhost:3306 I receive and error of connection filed
Anyway the mysql status thowme correct information, that it working ok!
Any idea ?
King regards
NatyHibernate 2.1.6
loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password="", hibernate.cglib.use_reflection_optimizer=true, hibernate.connection.pool_size=10, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://manoj/manoj, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver}
using CGLIB reflection optimizer
configuring from resource: /hibernate.cfg.xml
Configuration resource: /hibernate.cfg.xml
Mapping resource: com/mec/emp.hbm.xml
Mapping class: com.mec.Employee -> emp
Configured SessionFactory: null
processing one-to-many association mappings
processing one-to-one association property references
processing foreign key constraints
Using dialect: net.sf.hibernate.dialect.MySQLDialect
Maximim outer join fetch depth: 2
Use outer join fetching: true
Using Hibernate built-in connection pool (not for production use!)
Hibernate connection pool size: 10
using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://manoj/manoj
connection properties: {user=root, password=""}
No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Could not obtain connection metadata
java.sql.SQLException: Server configuration denies access to data source
at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:144)
at org.gjt.mm.mysql.Connection.<init>(Connection.java:230)
at org.gjt.mm.mysql.Driver.connect(Driver.java:126)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
at com.mec.CreateSession.getCurrentSession(CreateSession.java:35)
at com.mec.TestEmployee.createEmployee(TestEmployee.java:37)
at com.mec.TestEmployee.main(TestEmployee.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Use scrollable result sets: false
Use JDBC3 getGeneratedKeys(): false
Optimize cache for minimal puts: false
Query language substitutions: {}
cache provider: net.sf.hibernate.cache.EhCacheProvider
instantiating and configuring caches
building session factory
Not binding factory to JNDI, no JNDI name configured
SQL Error: 0, SQLState: 08001
Server configuration denies access to data source
Cannot open connection
java.sql.SQLException: Server configuration denies access to data source
at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:144)
at org.gjt.mm.mysql.Connection.<init>(Connection.java:230)
at org.gjt.mm.mysql.Driver.connect(Driver.java:126)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2231)
at com.mec.TestEmployee.createEmployee(TestEmployee.java:38)
at com.mec.TestEmployee.main(TestEmployee.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Process finished with exit code 0 -
CC&B deployment error - SPLWeb
Hi ,
We are trying to deploy CC&B (2.3.0) on Weblogic 10 MP2 and Oracle 11.1.0.7 & Windows 2003 Server 32bit.
We are deploying the SPLWeb.ear and SPLServices.ear in Weblogic. The SPLServices.ear was successfully deployed , but SPLWeb.ear is failing to deploy due to error as below:
2010-04-14 10:17:40,186 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$P
oolThread-#1] WARN (v2.resourcepool.BasicResourcePool) com.mchange.v2.resourcep
ool.BasicResourcePool$AcquireTask@55f079 -- Acquisition Attempt Failed!!! Cleari
ng pending acquires. While trying to acquire a needed new resource, we failed to
succeed more than the maximum number of allowed acquisition attempts (30). Last
acquisition attempt exception:
java.sql.SQLException: ORA-28000: the account is locked
The hibernate.properties files in the CC&B environment as given below: - (The username / password is correct as below)
hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
hibernate.connection.url = jdbc:oracle:thin:@01HW157263:1521:CCNB
hibernate.connection.username = CISUSER
hibernate.connection.password = CISUSER
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql = false
hibernate.max_fetch_depth = 2
hibernate.transaction.factory_class = org.hibernate.transaction.JDBCTransactionFactory
hibernate.jdbc.fetch_size = 100
hibernate.jdbc.batch_size = 30
hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.cache.use_second_level_cache = false
hibernate.query.substitutions = true 'Y', false 'N'
## Use C3P0 connection pooling, just define the below
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size = 1
hibernate.c3p0.max_size = 150
hibernate.c3p0.timeout = 300
hibernate.c3p0.max_statements = 0
#some other values seen elsewhere, might need tweaking
hibernate.c3p0.idle_test_period = 0
hibernate.c3p0.acquire_increment = 1
Please suggest how the problem can be solved.
Thanks and Regards
AntaraAccount was locked after 30 attempts (+FAILED_LOGIN_ATTEMPTS LIMIT on the PROFILE+) to establish a connection, probably you need to recheck the password supplied during user creation on the database for CISUSER.
Also passwords are case sensitive starting 11g, that too being optional; set by enabling/disabling case sensivity through SEC_CASE_SENSITIVE_LOGON initialization parameter. -
I've got a Seam app that needs to use a JNDI datasource file to connect to an Oracle 10g instance. I can create a connection manually in Eclipse and do a "Test Connection" successfully; however, I've not yet figured out how to get Eclipse to recognize the JNDI file with the identical credentials. Here's the persistence.xml file for the app:
<persistence-unit name="ora-forms" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/ora-forms</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/ora-forms"/> </properties> </persistence-unit>
Here's the hibernate-console.properties:
hibernate.connection.password= hibernate.connection.username= hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver hibernate.dialect=org.hibernate.dialect.Oracle10gDialect hibernate.connection.url= hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider hibernate.datasource=java:/ora-forms hibernate.transaction.manager_lookup_class=
When we try to use the "Seam Generate Entities" to read the database, it gives the following error:
Can't generate seam entities org.hibernate.exception.JDBCConnectionException: Getting database metadata Getting database metadata org.hibernate.exception.JDBCConnectionException: Getting database metadata Getting database metadata java.sql.SQLException: No suitable driver No suitable driverIs it easier to manage EJB's or servers using JMS and
JNDI technologies?I would read the j2ee tutorial or a good book on J2ee if I were you.
http://java.sun.com/developer/onlineTraining/index.html
Maybe you are looking for
-
TF80067 - Error while opening a project
Hi Starting yesterday I got this error when I open a project from Project Professional. The project lives on a Project Online PWA. I can't find information about this error... :-/
-
I have k7n2 delta L --6570--amdxp-2500-512 mb pc3200 ram. powmax 400w power .ati 9600 all in wonder. I swapped all parts to a better case to fit a certain location and the system will not post at all. the diagnostic d-bracket has number 1 and 4 in re
-
How do i stop my Yahoo email from auto signing me into it when i sign into firefox
when i sign into firefox, and if i have new email, my email auto opens when i sign into firefox. i don't have to give my password. in the bottom right part of the page, a box pops up and says i have (so many) new emails, there is a box to click on an
-
Can i use my ipod with this mac
Sorry if this was asked before, but my problem and question may be slightly different. I have an old 20 gig ipod that I've had since 1995. I have downloaded many songs from i-tunes and from my own cd's to my pc running widows xp. There are about 1300
-
Why does the update keep failing?
Every day for quite awhile I get a dialogue box saying the update failed. Otherwise Firefox works just fine.