public class TestManytoOne { public static void main(String[] args) { Configuration conf = new Configuration().configure(); SessionFactory sf = conf.buildSessionFactory(); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); Testtb user = new Testtb(); Address a = new Address("耶路撒冷"); user.setId("00000000001"); user.setName("ddddddddd"); user.setAddress(a.toString()); session.persist(user);//执行到这一步报的错 Address a2 = new Address("流沙河"); user.setAddress(a2.toString()); tx.commit(); session.close();
}
}
严重: IllegalArgumentException in class: dao.Address, getter method of property: addressId Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of dao.Address.addressId at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3605) at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3321) at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204) at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:535) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:93) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:637)
最新回答
旧梦时光机丶
2021-11-30 19:35:52
<id name="addressId" type="java.lang.Integer"> <column name="address_id"></column> <generator class="native"> <param name="sequence">testsequence</param> </generator> </id> 既然是配置一个Integer的值,为什么要用一个String类型的值? 还有就是和一楼的疑问一样,为什么要对Address a = new Address("耶路撒冷");中的a对象引用进行toString()方法呢?引用名.toString()你得到的结果将是 包名+类名+@十六进制的内存地址