orm

Should I close connection when using SessionFactoryUtils

If I want to use SessionFactoryUtils to get Connection directly to execute some SQL statement, and join the same transaction. Like this: SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection(); //some logic after Connection retrieved Do I have to close Connection by myself? or just let it be and Hibernate Session will h...

HIbernate loads subclasses along with classes

I am using Hibernate to connect to my database. I have an inheritance structure in my application.The problem is that when i do a query like "from Animal", it does a left outer join for the class Animal,its sub classes and all the associations for Animal and its subclasses. How do i avoid this situation.I want to load the data only when ...

Hibernation annotations, specify column default value

I have a domain object and annotated as follows @Entity @Table(name = "REQUEST") public class Request { /** * Unique id for this request */ @Id @GeneratedValue @Column(name = "EQ_ID") private long requestId; /** * */ @Column(name = "EMAIL_ID") private String emailId; /** * */ @Column(name = "REQUEST_DATE") private Date...

How to NOT select empty string

Hi. We have the following JPQL: Select distinct sys.ipAddress from SystemLog sys where sys.ipAddress is not null and sys.ipAddress is not empty And this generates the following mysql statement. select distinct systemlog0_.ipAddress as col_0_0_ from SystemLog systemlog0_ where ( systemlog0_.ipAddress is not nu...

JPA: difference between @JoinColumn and @PrimaryKeyJoinColumn?

What's the exact difference between @JoinColumn and @PrimaryKeyJoinColumn? You use @JoinColumn for columns that are FKs. A typical column could look like (e.g. in a join table with additional attributes): @ManyToOne @JoinColumn(name = "...") private OtherClass oc; What happens if I promote the column to be a/the PK, too (a.k.a. ident...

Why is an object found by id in JPA, but not through a JPQL query?

I have a JUnit 4 test case with the Spring @Transactional annotation that saves an object, and then attempts to find it. The test case passes when I use this implementation: @Override public EventSummary findEventSummaryById(Integer id) { return em.find(EventSummary.class, id); } It fails when I use this implementation (and then c...

JPA: When to choose Multivalued Association vs. Element Collection Mapping

I would like to better understand the differences between (1) a traditional Multivalued Relationship/Association @Entity -> @OneToMany -> @Entity and (2) the JPA2 Collection of Embeddable (and basic) Types @Entity -> @ElementCollection -> @Embeddable I see the syntactical differences, but wonder whether there are also ...

JPA - Change table at runtime

Hi, I have a problem Tables sales_2009 sales_2008 sales_2007 And only one class (sales), How change the table at runtime? ...

Why would I want to use POCO's?

I currently use the Entity Framework designer to generate my persistance objects and I also user POCO view models for the ASp.NET MVC view. I've read and listened to a lot of people talking about the good support for POCO's in EF4 as well as POCO's in general but I can't seem to work out what advantage, if any I'll get from using them. ...

One more column into join table using hibernate many-to-many

Hi! How i can map structure like this into class A{ Map<SomeEnum, B> foo; } where key in foo is representation of role in a_ has _b ? Thanks! ...

Query scalar collections in HQL

I have the following class: class User { String username; @CollectionOfElements private Set<String> roles = new HashSet<String>(); [many more things here] } And I want to write a HQL query that retrieves the username and the roles for all the users. Query query = session.createQuery("select distinct u.username, u.roles from User u");...

Is there any JPA fluent API / Critera api for JPA 1.0? I'm using OpenJPA

Is there any jpa 1.0 fluent api/interface for query building? I'm using openjpa 1.x, so I'm stuck with JPA1. I found QueryByProxy, but its maven repo is not working properly. ...

Which DAL approach to take?

ActiveRecord is too limiting normally. However, i'm in a difficult situation in terms of the views held by each member of the team in regards to using ORM's. We currently use a very basic ActiveRecord with regret I say is written mostly by hand with some basic generation of code. I would like to build a new DAL for us but avoiding the li...

Building UI of complex relational data with Sharepoint 2010?

We've got some relational data in SQL Server and would like to build a UI in Sharepoint 2010 to create and modify records. For simple tabular data it's straightforward, but what about master-detail structures where a single logical object is com posited from a number of tables? A large topic, but is there a basic course of action that i...

MySQL view to CSV file using Java, Spring, and Hibernate

I've been asked to output a CSV file from a view in MySQL. The app I currently am writing uses Spring and Hibernate to create the database, but the view is just handed to me. Hibernate doesn't know anything about this view, but I'd want to do something like this: public List<Object> getCsvView() { return (List<Object>) getHibernate...

persisting a new object without having to fetch the associations

I have the following mapping in an Ad entity: class Ad ... { @Id @Column(name = "id", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_ad_generator") private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id", nullable = false) ...

ORM and validation

I want to implement an ORM and validation libraries for it. Please suggest me how start work. Or suggest any developed library from where I got any idea. ...

How do you mix raw SQL with ORM APIs when you use django.db?

ORM tools are great when the queries we need are simple select or insert clauses. But sometimes we may have to fall back to use raw SQL queries, because we may need to make queries so complex that simply using the ORM API can not give us an efficient and effective solution. What do you do to deal with the difference between objects ret...

Dynamic hibernate mapping file

Here is an example of my mapping file: <!-- ============================ --> <!-- Table TABLE1 --> <!-- ============================ --> <class table="TABLE1" name="com.myCompany.Entity1" lazy="false" schema="SCHEMA1"> <!-- Attributs --> <id column="ID" name="id" type="string" /> <property column="ACTION_TYPE" name="acti...

What is best ORM with these requirements

I'm looking for a good ORM for an upcoming project. The database will have around 1000 to 1200 tables, and it will be in Both SQL Server and Oracle, which will be used depending of customers enterprise needs. Also a few part of the project will work with WCF services. I want a designer or something like that. Good support of LINQ. Accep...