hibernate-annotations

How to load only ids from Many to Many mapping tables?

自古美人都是妖i 提交于 2019-11-30 14:01:40
问题 In a Many to Many relation between two table with a Mapping table in between, how can I only load ids for the second entity. Following is the example to explain what I want to achieve here. Below is a sample schema create table user( id int PrimaryKey, name text ) create table pages ( id int PrimaryKey, page_name text ) create table user_page ( id_user int, id_page int, PrimaryKey (id_user, id_page) ) Note: there are additional columns in user and page tables which i have not included here

JPA/Hibernate DDL generation; CHAR vs. VARCHAR

≯℡__Kan透↙ 提交于 2019-11-30 13:57:54
问题 I have a JPA/Hibernate data model that I am using the Hibernate hbm2ddl tool to generate database DDL. I have some strings that should be CHAR and some that may be VARCHAR in the database. I want to minimize hand editing of the DDL (I realize that some will have to happen). Anyone know how I should go about this? I realize that I can make all Strings VARCHARS or CHARS via a hacked dialect, but that isn't what is always appropriate in the database. I would like to be able to do this with

Creating Indexes on DB with Hibernate @Index Annotation

a 夏天 提交于 2019-11-30 08:14:32
I have annotation-driven hibernate capabilies on my project. Now I want to create an index over a column. My current column definition is @NotNull @Column(name = "hash") private String hash; and I add @Index annotation here. @NotNull @Column(name = "hash") @Index(name="hashIndex") private String hash; and then DROP TABLE and restart Tomcat server. After the server is instantiated, the table is created but I can't see new index on following query. SHOW INDEX FROM tableName It is expected to construct table with new index. I am using InnoDB with MySQL. Interestingly, in my Hibernate

How can I mark a foreign key constraint using Hibernate annotations?

冷暖自知 提交于 2019-11-30 06:14:28
问题 I am trying to use Hibernate annotation for writing a model class for my database tables. I have two tables, each having a primary key User and Question. @Entity @Table(name="USER") public class User { @Id @Column(name="user_id") @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(name="username") private String username; // Getter and setter } Question Table. @Entity @Table(name="QUESTION") public class Questions extends BaseEntity{ @Id @Column(name="question_id")

hibernate composite Primary key contains a composite foreign key, how to map this

∥☆過路亽.° 提交于 2019-11-30 05:20:51
I searched there, and didn't find any similar topic, so I am posting a new question. I am working with Hibernate on an existing Database. The table structure and data we are not allowed to change. The application is reading data from the database and migrating to another datastore based on some logic. Now the problem is about a composite PK mapping. e.g. Table A has a composite PK. Table A -------- a1 (pk) a2 (pk) a3 (pk) a4 (pk) foo bar ======== Table B has a composite PK too, and one part of this composite PK is A's PK, here is working as FK as well. Table B -------- a1 (fk,pk) a2 (fk,pk) a3

Hibernate buildSessionFactory() Exception

白昼怎懂夜的黑 提交于 2019-11-30 03:31:10
问题 I have a serious problem with hibernate. I followed various books und online tutorials, but I ever get the same Exception "ExceptionInInitializerError" obviously thrown by the HibernateUtil.java Line SessionFactory sf = cfg.configure().buildSessionFactory(); My Tomcat log says the following: Caused by: java.lang.ExceptionInInitializerError at de.marcelstuht.nerven2.server.HibernateUtil.buildSessionFactory(HibernateUtil.java:23) at de.marcelstuht.nerven2.server.HibernateUtil.<clinit>

@ManyToOne and @BatchSize

半城伤御伤魂 提交于 2019-11-29 14:38:39
问题 I found in some old code strange thing (at least for me). The field which is annotated @ManyToOne is also annotated with @BatchSize . I always thought that @BatchSize annotation only affects when annotated at class level or on a collection ( @OneToMany ) and affects pre-fetching when iterating. But maybe I am wrong and annotating @ManyToOne with @BatchSize affects something. I can't find the answer in the documentation. Does annotating @ManyToOne with @BatchSize have sense? 回答1: @ManyToOne

Why is my EmbeddedId in hibernate not working?

我的未来我决定 提交于 2019-11-29 05:33:16
I have a compound Primary Key (IDHOLIDAYPACKAGE, IDHOLIDAYPACKAGEVARIANT) in table HolidayPackageVariant where IDHOLIDAYPACKAGE refers to entity HolidayPackage with a Many to One relationship between HolidayPackageVariant and HolidayPackage . When I try to do the compund PK mapping in HolidayPackageVariant, I get the following error: Initial SessionFactory creation failed.org.hibernate.annotations.common.AssertionFailure: Declaring class is not found in the inheritance state hierarchy: org.wah.model.holidaypackage.HolidayPackageVariantPrimaryKey Can someone please tell me what am I doing wrong

How to validate database schema programmatically in hibernate with annotations?

断了今生、忘了曾经 提交于 2019-11-29 04:52:06
It seems that org.hibernate.cfg.Configuration object can be used to perform validation programmatically, by calling the validateSchema method. However, this method needs dialect and databaseMetadata objects. I am using Spring and I can get a hold of AnnotationSessionFactoryBean object from spring context. So far I have the following code: AnnotationSessionFactoryBean factory = null; factory = (AnnotationSessionFactoryBean) context.getBean("AnnotationSessionFactory"); Configuration configuration = factory.getConfiguration(); //the following line does not work, ConnectionHelper hierarchy is not

hibernate composite Primary key contains a composite foreign key, how to map this

三世轮回 提交于 2019-11-29 03:15:21
问题 I searched there, and didn't find any similar topic, so I am posting a new question. I am working with Hibernate on an existing Database. The table structure and data we are not allowed to change. The application is reading data from the database and migrating to another datastore based on some logic. Now the problem is about a composite PK mapping. e.g. Table A has a composite PK. Table A -------- a1 (pk) a2 (pk) a3 (pk) a4 (pk) foo bar ======== Table B has a composite PK too, and one part