论坛首页 Java企业应用论坛

十分钟在jb里面运行hibernate的简单例子。

浏览 63136 次
该帖已经被评为精华帖
作者 正文
   发表时间:2003-10-23  
n+1次了,后面1000条要象前面3条一样加上事务。
0 请登录后投票
   发表时间:2003-10-23  
谢谢,问题确实在这儿。
0 请登录后投票
   发表时间:2003-11-04  
C:\Reveille\jdk1.4\bin\javaw -classpath "C:\Documents and Settings\hyf\jbproject\hibrernate\classes;C:\hibernate-2.1\lib\ant.jar;C:\hibernate-2.1\lib\c3p0.jar;C:\hibernate-2.1\lib\cglib-asm.jar;C:\hibernate-2.1\lib\commons-beanutils.jar;C:\hibernate-2.1\lib\commons-collections.jar;C:\hibernate-2.1\lib\commons-dbcp.jar;C:\hibernate-2.1\lib\commons-lang.jar;C:\hibernate-2.1\lib\commons-logging.jar;C:\hibernate-2.1\lib\commons-pool.jar;C:\hibernate-2.1\lib\connector.jar;C:\hibernate-2.1\lib\dom4j.jar;C:\hibernate-2.1\lib\jaas.jar;C:\hibernate-2.1\lib\jcs.jar;C:\hibernate-2.1\lib\jdbc2_0-stdext.jar;C:\hibernate-2.1\lib\jds.jar;C:\hibernate-2.1\lib\jgroups.jar;C:\hibernate-2.1\lib\jta.jar;C:\hibernate-2.1\lib\junit.jar;C:\hibernate-2.1\lib\odmg.jar;C:\hibernate-2.1\lib\optional.jar;C:\hibernate-2.1\lib\oscache.jar;C:\hibernate-2.1\lib\proxool.jar;C:\hibernate-2.1\lib\swarmcache.jar;C:\hibernate-2.1\lib\xalan.jar;C:\hibernate-2.1\lib\xerces.jar;C:\hibernate-2.1\lib\xml-apis.jar;C:\hibernate-2.1\hibernate2.jar;C:\Reveille\jdk1.4\lib\dt.jar;C:\Reveille\jdk1.4\lib\htmlconverter.jar;C:\Reveille\jdk1.4\lib\tools.jar;C:\Reveille\jdk1.4\jre\lib\charsets.jar;C:\Reveille\jdk1.4\jre\lib\jce.jar;C:\Reveille\jdk1.4\jre\lib\jsse.jar;C:\Reveille\jdk1.4\jre\lib\plugin.jar;C:\Reveille\jdk1.4\jre\lib\rt.jar;C:\Reveille\jdk1.4\jre\lib\sunrsasign.jar;C:\Reveille\jdk1.4\jre\lib\im\indicim.jar;C:\Reveille\jdk1.4\jre\lib\im\thaiim.jar;C:\Reveille\jdk1.4\jre\lib\ext\dnsns.jar;C:\Reveille\jdk1.4\jre\lib\ext\ldapsec.jar;C:\Reveille\jdk1.4\jre\lib\ext\localedata.jar;C:\Reveille\jdk1.4\jre\lib\ext\sunjce_provider.jar;C:\Reveille\jdk1.4\jre\javaws\javaws.jar;C:\Reveille\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;C:\Reveille\jdk1.4\demo\jfc\Java2D\Java2Demo.jar"  hibrernate.Hello
2003-11-4 18:30:24 net.sf.hibernate.cfg.Environment <clinit>

信息: Hibernate 2.1 beta 5

2003-11-4 18:30:24 net.sf.hibernate.cfg.Environment <clinit>

信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.borland.datastore.jdbc.DataStoreDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=Sample, hibernate.connection.url=jdbc:borland:dslocal:C:hibernate.jds, hibernate.connection.password=, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}

2003-11-4 18:30:24 net.sf.hibernate.cfg.Environment <clinit>

信息: using java.io streams to persist binary types

2003-11-4 18:30:24 net.sf.hibernate.cfg.Environment <clinit>

信息: using CGLIB reflection optimizer

2003-11-4 18:30:24 net.sf.hibernate.cfg.Configuration addClass

信息: Mapping resource: hibrernate/Message.hbm.xml

2003-11-4 18:30:25 net.sf.hibernate.cfg.Binder bindRootClass

信息: Mapping class: hibrernate.Message -> Messages

2003-11-4 18:30:25 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing one-to-many association mappings

2003-11-4 18:30:25 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing one-to-one association property references

2003-11-4 18:30:25 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing foreign key constraints

2003-11-4 18:30:25 net.sf.hibernate.dialect.Dialect <init>

信息: Using dialect: net.sf.hibernate.dialect.HSQLDialect

2003-11-4 18:30:25 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: Maximim outer join fetch depth: 1

2003-11-4 18:30:25 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: Use outer join fetching: false

2003-11-4 18:30:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

信息: Using Hibernate built-in connection pool (not for production use!)

2003-11-4 18:30:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

信息: Hibernate connection pool size: 1

2003-11-4 18:30:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

信息: using driver: com.borland.datastore.jdbc.DataStoreDriver at URL: jdbc:borland:dslocal:C:hibernate.jds

2003-11-4 18:30:25 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

信息: connection properties: {user=Sample, password=}

2003-11-4 18:30:25 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup

信息: No TransactionManagerLookup configured (use of process level read-write cache is not recommended)

java.lang.NoClassDefFoundError: com/borland/dx/dataset/DataSetException

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.newInstance0(Class.java:278)

at java.lang.Class.newInstance(Class.java:261)

at com.borland.datastore.jdbc.DataStoreDriver.connect(Unknown Source)

at java.sql.DriverManager.getConnection(DriverManager.java:512)

at java.sql.DriverManager.getConnection(DriverManager.java:140)

at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:95)

at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)

at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1023)

at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:716)

at hibrernate.Hello.main(Hello.java:32)

Exception in thread "main"
0 请登录后投票
   发表时间:2003-11-12  
不好意思,来麻烦各位了,但这个错误我实在搞不定啊:org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence
在网上搜了一下,有人说也许是因为xml文件头没加:<?xml version="1.0" encoding="UTF-8"?>,但我加了也无济于事。不解……

详细信息如下:

     [exec] 2003-11-12 20:58:29 net.sf.hibernate.cfg.Environment <clinit>
     [exec] 信息: Hibernate 2.1 beta 5
     [exec] 2003-11-12 20:58:29 net.sf.hibernate.cfg.Environment <clinit>
     [exec] 信息: loaded properties from resource hibernate.properties: {hiberna
te.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflecti
on_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.Hashtab
leCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate
.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdb
c.batch_size=30, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N',
hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hiberna
te.connection.url=jdbc:mysql://localhost:5432/hibernate, hibernate.show_sql=true
, hibernate.connection.password=root, hibernate.statement_cache.size=25, hiberna
te.connection.pool_size=1}
     [exec] 2003-11-12 20:58:30 net.sf.hibernate.cfg.Environment <clinit>
     [exec] 信息: using java.io streams to persist binary types
     [exec] 2003-11-12 20:58:30 net.sf.hibernate.cfg.Environment <clinit>
     [exec] 信息: using CGLIB reflection optimizer
     [exec] 2003-11-12 20:58:30 net.sf.hibernate.cfg.Configuration addClass
     [exec] 信息: Mapping resource: hello/Message.hbm.xml
     [exec] 2003-11-12 20:58:32 net.sf.hibernate.cfg.Configuration addInputStrea
m
     [exec] 严重: Could not configure datastore from input stream
     [exec] org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence
. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.
     [exec]     at org.dom4j.io.SAXReader.read(SAXReader.java:358)
     [exec]     at net.sf.hibernate.cfg.Configuration.addInputStream(Configurati
on.java:266)
     [exec]     at net.sf.hibernate.cfg.Configuration.addClass(Configuration.jav
a:307)
     [exec]     at hello.Hello.main(Unknown Source)
     [exec] Nested exception:
     [exec] java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 seque
nce.
     [exec]     at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Sour
ce)
     [exec]     at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
     [exec]     at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
     [exec]     at org.apache.xerces.impl.XMLEntityScanner.scanData(Unknown Sour
ce)
     [exec]     at org.apache.xerces.impl.XMLScanner.scanComment(Unknown Source)

     [exec]     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCom
ment(Unknown Source)
     [exec]     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Fragmen
tContentDispatcher.dispatch(Unknown Source)
     [exec]     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDoc
ument(Unknown Source)
     [exec]     at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Sour
ce)
     [exec]     at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Sour
ce)
     [exec]     at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
     [exec]     at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Sou
rce)
     [exec]     at org.dom4j.io.SAXReader.read(SAXReader.java:339)
     [exec]     at net.sf.hibernate.cfg.Configuration.addInputStream(Configurati
on.java:266)
     [exec]     at net.sf.hibernate.cfg.Configuration.addClass(Configuration.jav
a:307)
     [exec]     at hello.Hello.main(Unknown Source)
     [exec] net.sf.hibernate.MappingException: Error reading resource: hello/Mes
sage.hbm.xml
     [exec]     at net.sf.hibernate.cfg.Configuration.addClass(Configuration.jav
a:310)
     [exec]     at hello.Hello.main(Unknown Source)
     [exec] Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentExce
ption: Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1
of 1-byte UTF-8 sequence.
     [exec]     at net.sf.hibernate.cfg.Configuration.addInputStream(Configurati
on.java:275)
     [exec]     at net.sf.hibernate.cfg.Configuration.addClass(Configuration.jav
a:307)
     [exec]     ... 1 more
     [exec] Caused by: org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF
-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.
     [exec]     at org.dom4j.io.SAXReader.read(SAXReader.java:358)
     [exec]     at net.sf.hibernate.cfg.Configuration.addInputStream(Configurati
on.java:266)
     [exec]     ... 2 more
     [exec] Exception in thread "main"
     [exec] Result: 1
0 请登录后投票
   发表时间:2003-11-13  
讨论过n遍了,搜索一下
0 请登录后投票
   发表时间:2003-12-16  
getdown 写道
看看Message.hbm.xml就很清楚了:

MESSAGE_ID BIGINT
TEXT VARCHAR(100)
NEXT_MESSAGE_ID BIGINT

就一个表自己关联

1、插入数据时每条记录的NEXT_MESSAGE_ID 值是如何保存的,2、Message.hbm.xml中的many to one 能不能讲解一下他的运作思想
0 请登录后投票
   发表时间:2003-12-23  
我是JB7。mysql数据库运行完后报错。请各位老大多多帮助。谢了。


0 [main] INFO cfg.Environment  - Hibernate 2.0 beta 5

16 [main] INFO cfg.Environment  - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.jdbc.fetch_size=50 , hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.batch_size=25, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost/roller, hibernate.connection.password=, hibernate.connection.pool_size=1 , hibernate.statement_cache.size=25 }

47 [main] INFO cfg.Environment  - using CGLIB reflection optimizer

47 [main] INFO cfg.Environment  - JVM proxy support: true

63 [main] INFO cfg.Configuration  - Mapping resource: myhibernate/Message.hbm.xml

329 [main] INFO mapping.Collection  - Mapping class: myhibernate.Message -> hibernetfirst

938 [main] INFO impl.SessionFactoryImpl  - building session factory

954 [main] INFO dialect.Dialect  - Using dialect: net.sf.hibernate.dialect.MySQLDialect

java.lang.NumberFormatException: 1

at java.lang.Integer.parseInt(Integer.java:435)

at java.lang.Integer.parseInt(Integer.java:476)

at net.sf.hibernate.util.PropertiesHelper.getInt(PropertiesHelper.java:18)

at net.sf.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:39)

at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:75)

at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:146)

at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:594)

at myhibernate.Hello.main(Hello.java:46)

Exception in thread "main"
0 请登录后投票
   发表时间:2003-12-30  
我的错误更加奇怪了.
    Message message;
    long start = System.currentTimeMillis();
    try {
      for (int i = 0; i < 1000; i++) {
        message = new Message("hello" + i);
        session.save(message);
        session.flush();
      }
      tx.commit();
    } catch (HibernateException ex) {
      tx.rollback();
      System.out.println(ex.toString());
    }
    long end = System.currentTimeMillis();
    System.out.println("添加1000条记录时间---" + (end-start)/1000 + "s");
错误讯息:net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: hello.Message
环境jbuilerX+mysql4.0.19+mysql jdbc 3.0.9+Hibernat 2.1
0 请登录后投票
   发表时间:2004-01-07  
我这里也出现了问题,不过可能是我的jbuilder用的不好,希望哪位高人能指点一下。
按照楼主的方法,我做好了一个project,编译没有问题,运行时选用run-->hello,结果弹出一个对话框:
Stopped in class with tracing disabled

Hit breakpoint in class java.net.URLClassLoader$1.Tracing is disabled for this class.



        

想知道我到底在什么地方有问题?

现在又有新的报错信息
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hit uncaught exception net.sf.hibernate.MappingException
net.sf.hibernate.MappingException: Resource: hello/Message.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:320)
at hello.Hello.main(Hello.java:24)
Exception in thread "main"
0 请登录后投票
   发表时间:2004-01-08  
已经搞好了,我没有把log4j.properties copy过来,不过没有看到哪篇文章里提到过这个,请问这是什么原因?

环境:win2000+jbuilder9+mysql4.0.17+hibernate2.1
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics