Tag: jpa

JPA中的多个唯一约束

有没有一种方法来指定使用JPA,应该有不同的列集上的多个唯一约束? @Entity @Table(name="person", uniqueConstraints=@UniqueConstraint(columnNames={"code", "uid"})) public class Person { // Unique on code and uid public String code; public String uid; // Unique on username public String username; public String name; public String email; } 我已经看到一个冬眠特定的注释,但我试图避免供应商的具体解决scheme,因为我们仍然决定hibernate和数据核心之间。

Spring CrudRepository findByInventoryIds(List <Long> inventoryIdList) – 相当于IN子句

在Spring CrudRepository中,我们是否支持一个字段的“IN子句”? 即类似于以下内容? findByInventoryIds(List<Long> inventoryIdList) 如果这种支持不可用,可以考虑哪些优雅的选项? 为每个ID触发查询可能不是最佳的。

如何生成JPA 2.0元模型?

本着与CriteriaQuery相关的types安全的精神,JPA 2.0还有一个API来支持实体的元模型表示。 是否有人知道这个API的全function实现(生成元模型,而不是手动创build元模型类)? 如果有人知道在Eclipse中设置这个步骤(我认为这与设置注释处理器一样简单,但你永远不知道),这将是非常棒的。 编辑:只是偶然发现Hibernate JPA 2元模型生成器 。 但问题仍然存在,因为我找不到任何jar的下载链接。 编辑2:自从我问这个问题以来已经过去了,但是我想我会回来并添加一个链接到SourceForge上的Hibernate JPA Model Generator项目

不能使用<union-subclass>(TABLE_PER_CLASS)标识列密钥生成

com.something.SuperClass: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class SuperClass implements Serializable { private static final long serialVersionUID = -695503064509648117L; long confirmationCode; @Id @GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!! public long getConfirmationCode() { return confirmationCode; } public void setConfirmationCode(long confirmationCode) { this.confirmationCode = confirmationCode; } } com.something.SubClass: @Entity public abstract class Subclass extends SuperClass { private […]

hibernate问题 – “使用@OneToMany或@ManyToMany定位未映射的类”

我正在用Hibernate Annotationsfind自己的脚,我碰到了一个问题,我希望有人能帮上忙。 我有2个实体,Section和ScopeTopic。 Section有一个List类成员,所以是一对多的关系。 当我运行我的unit testing时,我得到这个exception: 使用@OneToMany或@ManyToMany定位未映射的类:com.xxx.domain.Section.scopeTopic [com.xxx.domain.ScopeTopic] 我会假设错误意味着我的ScopeTopic实体没有映射到表? 我看不到我做错了。 这里是实体类: @Entity public class Section { private Long id; private List<ScopeTopic> scopeTopics; public Section() {} @Id public Long getId() { return id; } public void setId(Long id) { this.id = id; } @OneToMany @JoinTable(name = "section_scope", joinColumns = {@JoinColumn(name="section_id")}, inverseJoinColumns = {@JoinColumn(name="scope_topic_id")} ) public List<ScopeTopic> […]

从Java / JPA调用存储过程

我正在写一个简单的Web应用程序来调用存储过程并检索一些数据。 它是一个非常简单的应用程序,它与客户端的数据库交互。 我们传递员工ID和公司ID,存储过程将返回员工详细信息。 Web应用程序无法更新/删除数据并正在使用SQL Server。 我正在使用Jboss AS部署我的Web应用程序。 我应该使用JPA来访问存储过程或CallableStatement 。 在这种情况下使用JPA的任何好处。 还有什么将是SQL语句来调用这个存储过程。 我以前从来没有使用过存储过程,而我正在为这个而苦苦挣扎。 谷歌没有太多的帮助。 这里是存储过程: CREATE procedure getEmployeeDetails (@employeeId int, @companyId int) as begin select firstName, lastName, gender, address from employee et where et.employeeId = @employeeId and et.companyId = @companyId end 更新: 对于使用JPA调用存储过程的其他人来说。 Query query = em.createNativeQuery("{call getEmployeeDetails(?,?)}", EmployeeDetails.class) .setParameter(1, employeeId) .setParameter(2, companyId); List<EmployeeDetails> result = […]

如何使用spring-data-jpa更新实体?

那么问题几乎说了一切。 使用JPARepository如何更新实体? JPARepository只有一个保存方法,它不会告诉我它是实际创build还是更新。 例如,我向数据库用户插入一个简单的对象,它有三个字段:名字和姓氏和年龄: @Entity public class User { private String firstname; private String lastname; //Setters and getters for age omitted, but they are the same as with firstname and lastname. private int age; @Column public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } @Column public String getLastname() […]

使用JPA存储映射<String,String>

我想知道是否有可能使用注解来持久化attributes映射在下面的类使用JPA2 public class Example { long id; // …. Map<String, String> attributes = new HashMap<String, String>(); // …. } 由于我们已经有了一个预先存在的生产数据库,所以理想情况下attributes的值可以映射到下面的现有表: create table example_attributes { example_id bigint, name varchar(100), value varchar(100));

如何将Javadate存储到MySQLdate时间…?

任何机构可以告诉我如何将Javadate存储到MySQLdate时间…? 当我正在尝试这样做…只有date存储和时间保持00:00:00在这样的Mysqldate商店… 2009-09-22 00:00:00 我不仅要约会,而且还要时间…像 2009-09-22 08:08:11 我使用弹簧mydomain类JPA(hibernate)使用java.util.Date,但我已经创build了使用手写查询表… 这是我创造的声明 CREATE TABLE ContactUs (id BIGINT auto_increment, userName VARCHAR(30), email VARCHAR(50), subject VARCHAR(100), message VARCHAR(1024), messageType VARCHAR(15), contactUsTime datetime, primary key(id)) TYPE=InnoDB;

Google App Engine上的JDO与JPA for Java

我想用Struts2在Google App Engine上开发我的项目。 对于数据库我有两个选项JPA和JDO。 请问你们能给我build议吗? 两者对我来说都是新的,我需要学习它们。 所以我会在回复之后专注于一个。 谢谢。