orm

Embedding Generic Types in JPA

Does JPA support embedding a class attribute whose type is a parameterized generic or java.lang.Object? For example: public class Foo<T>; { private T param1; private Object param2; } I have a use case where I have a class that "wraps" some arbitrary class (the generic T or java.lang.Object) via aggregation plus contains pr...

Persisting deep object graph with JPA without em.flush()

I have following model: Report, ReportSection and ReportSectionProperty. Report has zero to many ReportSections, ReportSection has zero to many ReportSectionPropert-ies. This would qualifie as three levels deep object graph. I create new Report, then add some sections to it, then add some properties to it. When I try to persist Report...

Hibernate type used to map java.lang.Double

Hello, I am using "double" in Hibernate .hbm.xml files, and when I generate classes with Hibernate Tool I get class property which has primitive type double. I want this property to be java wrapper type Double. How can I achieve this? If I change this manually in my classes, is it going to give any issues to hibernate? Thanks ...

How do i use HibernateTemplate.findByNamedParam() ??

HI, i am trying to use the above spring hibernate temnplate method do a simple query based on a specific ID from the database but the problem is that the query doesnt replace the ":" character from the sql string below into the value contained in "id". i thought that this method replaces ":" with the given parameter i set in the method ...

How do I delete a row in a join table automatically, to avoid a ConstraintViolationException?

This seems like it should be a pretty simple question, or at least have a simple answer. But - I'm really not a database guy, and I'm still pretty far down on the Hibernate learning curve. That said, here's the setup: Consider a unidirectional many-to-many relationship between two entities, from Foo to Bar: (pardon any typos below, th...

Hibernate - Perform HQL query on Criteria Result

Hi @ all, I am concerned with a problem regarding criteria and hql. In first step a complex criteria construction limits a big amount of datasets. In second step a hql calculation should be performed on these preselected datasets of step one. The problem is that the code of both has been developed seperately and i am wondering if it is...

Why has Hibernate switched to use LONG over CLOB?

It looks like that Hibernate started using LONG data type in version 3.5.5 (we upgraded from 3.2.7) instead of CLOB for the property of type="text". This is causing problems as LONG data type in Oracle is an old outdated data type (see http://www.orafaq.com/wiki/LONG) that shouldn’t be used, and tables can’t have more than one column ha...

Manage persistent context before flushing

hi, consider hibernate-link and JTA as peristence provider. How can I force em not to flush anything, and to handle it by myself? @Stateless public class SomeBean{ @PersistenceContext EntityManager em; public void method(){ em.persist(entity); // will get managed em.clear(); // everything gets unmanaged } } I would ex...

Hibernate Polymorphism (Extending Parent Class)

Question regarding Hibernate Polymorphism and extending a parent class (which I can not modify directly). My parent class is called Contact: @Entity @Table(name="contact") @Inheritance(strategy=InheritanceType.JOINED) public class Contact { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) public long id; public String name;...

Why does eclipselink/jpa attempt to persist an entity while I don't ask it to?

I'm trying to persist 3 entities (exp,def,meng) in a transaction, and then persist another 2 (def', meng'), where meng' is related to exp. However, as I attempt to persist meng' eclipselink/jpa2 is being told to: Call: INSERT INTO EXPRESSION (EXPRESSION, GENDER) VALUES (?, ?) bind => [exp, null] which will throw an expession sinc...

Hibernate: Risks associated with changing DiscriminatorValue

Given: @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="postType", discriminatorType=DiscriminatorType.STRING) public class Post {} @DiscriminatorValue(value = PostType.BUG) public class BugReport extends Post {} That is ... Bugs start life in this system as a Post. Later, they can be promoted(?) to bei...

In Ruby on Rails, if you have the association wrong in the models, will it affect your app if you only touch model.instance_variable?

That is, if you have all the has_many, has_one, belongs_to, and has many ... :through and has_many_and_belongs_to wrong, but your program only touch the model.instance_variable but not model.some_other_model # or model.some_other_model.some_method_or_variable will you app do anything wrong or do anything bad to the database? Th...

Hibernate: fetching a set of objects in an entity mapping

Hi guys, I've got an entity Case that has an id CaseId (unfortunately a string due to compability with a legacy system). This id is foreign key in the table Document, and each Case can have many documents (onetomany). I've put the following in my Case entity: @Id @Column(name = "CaseId", length = 20, nullable = false) private String ca...

cannot insert null in one to many relatioship hibernate annotation

I have a class A{Set b .....} which holds references of class B as Set. It is one to many relationship. Both class have sequencer in oracle. I put cascade to all in hibernate annotations. When i save class A, it gives me error that cannot insert null B.a_id . A-id is not nullable in my database. How can i persist this relatioship. ...

Alternative solutions for Hibernate.Envers

Hi, i'm planning a historization for my java webapp (spring, hibernate). By googling I found Hibernate.Envers, which seems to be the perfect solution for me. Are there any comparable solutions? Thanks a lot! Jean ...

How to create indexes on multiple columns

We have the following entity relationships where a User belongs to a particular Organization. My queries either look like "select * from User where org=:org" or "select * from User where org=:org and type=:type" I have separate indexes on the User class. The first query will be fine, because of the Index on the foreign key element. Does...

Visual Studio - auto generate entities and web front end?

Hey all, I went to the Visual Studio 2010 launch and remember seeing someone generate entites (which I am using and is awesome) from a database, but then taking it a step further and creating a web front end. The front end would allow modification/deletion of existing data and addition of new, and it was all generated. It was ugly, of...

nhibernate insert question - have id but not entity object

Using NHibernate I need to insert an entity into a database that has a child entity. Example: public class Reservation { public int Id { get; set; } public Service Service { get; set; } } public class Service { public int Id { get; set; } } I need to create a new Reservation and insert it. However, when constructing the R...

Hibernate Inheritance Modeling

Hi All, I'm having trouble creating a model for a couple entities that is sane in both Hibernate and the Database. Any help is appreciated. A company entity and table exists, which provides both a company name and a "company code". The company code must be unique. Company's may act as 2 different entities, clients or partners. We'd ...

The best way to interact with a database, with objects

Alright, so after years of feeling that I've been doing it the wrong way, what is the best way to interact with a MySQL database, using PHP. Going to start off small-scale, but eventually hoping to grow large scale. I'd love to be able to use objects, like such $book = new Book(1342); echo $book->title; So, what is the best way to go...