Tag: hibernate mapping

javax.persistence对field,getter或setter的注释?

我目前正在学习Hibernate和Java Persistence API。 我有一个@Entity类,需要将注释应用于各个字段。 我已经在下面的代码中包含了他们可以去的所有三个地方。 我应该将它们应用于野外本身,吸气剂还是吸尘器? 这三个选项之间的语义差异(如果有的话)是什么。 import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Id; @Entity @Table(name = “song”) public class Song { // Annotations should only be applied to one of the below @Id @Column(name=”id”, unique=true, nullable=false) private int id; @Id @Column(name=”id”, unique=true, nullable=false) public int getId() { return id; } @Id @Column(name=”id”, unique=true, nullable=false) public […]

收到org.hibernate.TypeMismatchExceptionexception

我正在使用Spring使用Spring使用SpringMVC,我遇到了以下错误,我不知道如何处理它。 现在我在控制台中有这条消息: org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878) at org.hibernate.impl.SessionImpl.load(SessionImpl.java:795) at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301) at com.sun.proxy.$Proxy11.load(Unknown Source) at com.my.dao.DepartementImplDB.getDepartementByNom(DepartementImplDB.java:54) at com.my.dao.DepartementImplDB.addDepartement(DepartementImplDB.java:29) at com.my.service.DepartementImplMetier.create(DepartementImplMetier.java:57) at com.my.controller.ImportController.Read(ImportController.java:279) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at […]

Postgresql枚举和Java枚举之间的Hibernate映射

背景 Spring 3.x,JPA 2.0,Hibernate 4.x,Postgresql 9.x. 使用我要映射到Postgresql枚举的枚举属性处理Hibernate映射类。 问题 在枚举列上使用where子句进行查询会引发exception。 org.hibernate.exception.SQLGrammarException: could not extract ResultSet … Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: movedirection = bytea Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 代码(大大简化) SQL: create type movedirection as enum ( ‘FORWARD’, ‘LEFT’ ); […]

为什么我会获得映射exception?

我正进入(状态 : org.hibernate.MappingException: Foreign key (FKBB979BF4266AA123:address [a_id])) must have same number of columns as the referenced primary key (address [p_id,a_id]) 当我尝试运行以下(虽然不完整)片段时: public static void main(String args[]) { Configuration config = new Configuration().configure(); SessionFactory sessFact = config.buildSessionFactory(); Session sess = sessFact.openSession(); Transaction trans = sess.beginTransaction(); } hibernate mapping xml如下所示: 我正在尝试Person和Address类之间的many to many关联。 这个例外的原因是什么? 我使用这些sql命令创建了两个表person和address : CREATE […]

通过查询来hibernate多对多数据检索

请帮助我,我认为有些事情我做得不对。 我有User和Contact ,这是Many-to-Many关系。 User.java: public class User { private Integer userID; private String userLoginEmail; private Set contactSet = new HashSet(); public User() { } . getters and setters . Contact.java public class Contact implements Serializable { private Integer contactID; private Set userSet= new HashSet(); public Contact() { } . getters and setters . . 用户映射: […]

Java Hibernate映射exception! (无法确定类型:java.util.Map)

我创建了一个名为Movie的课程,其中包括以下字段: @Id @GeneratedValue private Long id; private String name; @ElementCollection(targetClass = String.class) private Map properties; private Double rate; private Integer votersCount; private Date releaseDate; private Integer runtime; @ManyToMany @JoinTable(name = “movie_director”) @IndexColumn(name = “directorIndex”) private List directors; @ManyToMany @JoinTable(name = “movie_writer”) @IndexColumn(name = “writerIndex”) private List writers; @OneToMany @IndexColumn(name = “roleIndex”) private List movieRoles; @ManyToMany […]

无法创建sessionFactory object.org.hibernate.InvalidMappingException:无法解析资源Employee.hbm.xml中的映射文档

这是我的Employee.hbm.xml This class contains the employee detail. 在运行hibernate时,我得到以下exception Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml Exception in thread “main” java.lang.ExceptionInInitializerError at com.demo.hibernate.beans.ManageEmployee.main(ManageEmployee.java:20) Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:575) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1561) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514) at org.hibernate.cfg.Configuration.configure(Configuration.java:1434) at org.hibernate.cfg.Configuration.configure(Configuration.java:1420) at com.demo.hibernate.beans.ManageEmployee.main(ManageEmployee.java:17) […]

java.lang.NoSuchMethodError:javax.persistence.OneToMany.orphanRemoval()

我有一个maven项目,使用spring,hibernate(3.6.4),GWT(2.3),drools,….一切都很好,直到我开始使用hibernate OneToMany,ManyToMany关系…… 当我从“mvn jetty:run”运行应用程序时,它可以工作,但是当我从gwt嵌入式jetty运行应用程序时,从我在应用程序中嵌入的jetty版本运行时,我得到: [INFO] Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z [INFO] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912) [INFO] at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796) [INFO] at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707) [INFO] at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035) [INFO] at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989) [INFO] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398) [INFO] at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375) [INFO] at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717) [INFO] at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) [INFO] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [INFO] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [INFO] … 95 more 这些是jar子: [INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile [INFO] +- junit:junit:jar:4.8.2:test [INFO] +- […]

HIbernate映射exception:PropertyNotFoundException:找不到setter

我有两个POJO,STOCK和STOCK_DETAILS(一对多的关系)。 我还有一个接口IAUDITLOG(有两种方法)。 我需要用BOTH POJO实现这个接口,并希望在这些方法中编写一些实现。 但是当我用子类“STOCKDETAILS”实现IAUDITLOG接口时,它会给出exception“你应该有setter属性” 股票类别: @Entity @Table(name = “stock”) public class Stock implements java.io.Serializable, IAuditLog { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = “id”) private Integer stockId; @Column(name = “STOCK_CODE”) private String stockCode; @Column(name = “STOCK_NAME”) private String stockName; @OneToMany( fetch = FetchType.LAZY, mappedBy = “stock”) public Set stockDetails = new HashSet(0); […]

Hibernate包vs idbag

我已经看了一个包和idbag之间的区别,我理解它们之间的区别,但我想要了解的是,如果使用包而不是idbag,反之亦然会有一些情况可能会出错。 有人可以用一个例子解释这个。