该帖已经被评为精华帖
|
|
---|---|
作者 | 正文 |
发表时间:2004-01-12
回应vilico,foreign 是sql的术语,就是foreign key,一般如果牵涉到2张表的话,就要有foreign key作为对应。
比如说,如果您有student+address这2个资料,如果没有一个key把这2个东西接在一起,请问如何知道这个学生是这个地址,那个地址又是另外一个学生? 另外一个我就不会了。 |
|
返回顶楼 | |
发表时间:2004-01-24
能不能说一下在one2one情况下使用Lazy的用法,我试过很多次都不行.
|
|
返回顶楼 | |
发表时间:2004-02-11
各位老兄,我是Hibernate新手,照着帖子做的程序有两个问题:
1. 帖子中InputStream stream = Example.class.getResourceAsStream("hibernate.properties"); 找不到hibernate.properties,我换成FileInputStream stream = new FileInputStream("hibernate.properties"); 就ok了? 2. 在one -to -one 中,我运行后在两个表(person,author)中哥插入了一条记录,但是在author表中person字段却是空的?? 我用的数据库是mysql ,谢谢! |
|
返回顶楼 | |
发表时间:2004-02-18
怎样调试这个代码?
|
|
返回顶楼 | |
发表时间:2004-03-03
用这种方式创建的一对一的关系,在删除的时候为什么不能级连删除
|
|
返回顶楼 | |
发表时间:2004-03-27
/** * @author kiki * * date 2004-3-26 * company www.pansky.com.cn */ package com.javamodel.hibernate; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import net.sf.hibernate.HibernateException; import net.sf.hibernate.MappingException; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Transaction; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.tool.hbm2ddl.SchemaExport; public class Example { private static SessionFactory _sessions=null; private static Properties pops=new Properties();; static{ try{ InputStream stream=Example.class.getResourceAsStream ("hibernate.properties");; try{ pops.load(stream);; }catch(IOException e1);{ e1.printStackTrace();; } Configuration cfg=new Configuration();; cfg.addClass(Person.class);; cfg.addClass(Author.class);; cfg.setProperties(pops);; //new SchemaExport(cfg);.create(true,true);; _sessions=cfg.buildSessionFactory();; }catch(MappingException e);{ e.printStackTrace();; }catch(HibernateException e);{ e.printStackTrace();; } } public static void main(String[] args);throws HibernateException{ Person person=new Person();; //person.setName("HengfeiDo");; //person.setEmail("smallduzi@sohu.com");; Author author=new Author();; //author.setAlias("smallduzi");; //author.setPerson(person);; Session session=_sessions.openSession();; Transaction tx=null; try{ tx=session.beginTransaction();; Query query=session.createQuery("from Person as person where person.id=:id");; query.setString("id","5d8f3210fb8a972c00fb8a9758970001");; person=(Person);query.list();.get(0);; person.setName(person.getName();+"老大");; author.setPerson(person);; //System.out.println(person.getId();+":"+person.getName();+":"+person.getEmail(););; session.save(author);; //session.delete(author);; tx.commit();; }catch(HibernateException he);{ if(tx!=null);tx.rollback();; throw he; } finally{ session.close();; } } } 错误信息 net.sf.hibernate.JDBCException: Could not execute JDBC batch update at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129); at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385); at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335); at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204); at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61); at com.javamodel.hibernate.Example.main(Example.java:68); Caused by: java.sql.BatchUpdateException: ORA-00001: 违反唯一约束条件 (SYSTEM.SYS_C002552); at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459); at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907); at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54); at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122); ... 5 more Exception in thread "main" 为什么??? |
|
返回顶楼 | |
发表时间:2004-03-27
信息: no JNDI name configured
java.lang.NoClassDefFoundError: javax/transaction/Synchronization at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:312) at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:325) at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:333) at hiberante.Example.main(Example.java:50) Exception in thread "main" 是为什么?? |
|
返回顶楼 | |
发表时间:2004-04-06
To:kiki
原因就是主键冲突,因为你的person是取出来的,是有ID的,你有将它Insert,你想会不会出错.你要新NEW一个person才可以. Person myPerson = new Person(); myPerson.setName(person.getName()+"老大"); author.setPerson(myPerson); |
|
返回顶楼 | |
发表时间:2004-04-08
flyfox2008 写道 To:kiki
原因就是主键冲突,因为你的person是取出来的,是有ID的,你有将它Insert,你想会不会出错.你要新NEW一个person才可以. Person myPerson = new Person(); myPerson.setName(person.getName()+"老大"); author.setPerson(myPerson); 你这样不是更新,它又重新插入了一条记录 |
|
返回顶楼 | |
发表时间:2004-04-08
11:18:59,015 ERROR JDBCExceptionReporter:38 - could not insert: [com.javamodel.hibernate.Author#408283fafbc8201900fbc8201c790001] com.jnetdirect.jsql.v: 对象名 'author' 无效。 晕啊,看了下,发现楼主的程序中没有建表,只好自己建了 |
|
返回顶楼 | |