Author: epbernard
Date: 2007-01-16 19:40:54 -0500 (Tue, 16 Jan 2007)
New Revision: 11052
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
Log:
ANN-516 support for @OrderBy and @Inheritance(JOINED)
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-16
23:24:17 UTC (rev 11051)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-17
00:40:54 UTC (rev 11052)
@@ -836,11 +836,19 @@
+ associatedClass.getEntityName() + "." + property
);
}
-
+ PersistentClass pc = p.getPersistentClass();
+ String table;
+ if (pc != associatedClass) {
+ table = pc.getTable().getQuotedName() + ".";
+ }
+ else {
+ table = "";
+ }
Iterator propertyColumns = p.getColumnIterator();
while ( propertyColumns.hasNext() ) {
Selectable column = (Selectable) propertyColumns.next();
- orderByBuffer.append( column.getText() )
+ orderByBuffer.append( table )
+ .append( column.getText() )
.append( " " )
.append( ordering.get( index ) )
.append( ", " );
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-01-16
23:24:17 UTC (rev 11051)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-01-17
00:40:54 UTC (rev 11052)
@@ -7,6 +7,7 @@
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.Set;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
@@ -377,6 +378,27 @@
s.close();
}
+ public void testOrderByOnSuperclassProperty() {
+ OrganisationUser user = new OrganisationUser();
+ user.setFirstName( "Emmanuel" );
+ user.setLastName( "Bernard" );
+ user.setIdPerson( new Long(1) );
+ user.setSomeText( "SomeText" );
+ Organisation org = new Organisation();
+ org.setIdOrganisation( new Long(1) );
+ org.setName( "S Diego Zoo" );
+ user.setOrganisation( org );
+ Session s = openSession();
+ s.getTransaction().begin();
+ s.persist( user );
+ s.persist( org );
+ s.flush();
+ s.clear();
+ List l = s.createQuery( "select org from Organisation org left join fetch
org.organisationUsers" ).list();
+ s.getTransaction().rollback();
+ s.close();
+ }
+
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
@@ -396,7 +418,10 @@
City.class,
Street.class,
PoliticalParty.class,
- Politician.class
+ Politician.class,
+ Person.class,
+ Organisation.class,
+ OrganisationUser.class
};
}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java 2007-01-16
23:24:17 UTC (rev 11051)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Organisation.java 2007-01-17
00:40:54 UTC (rev 11052)
@@ -0,0 +1,60 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table( name = "ORGANISATION" )
+public class Organisation implements Serializable {
+
+ private Long idOrganisation;
+ private String name;
+ private Set<OrganisationUser> organisationUsers;
+
+ public Organisation() {
+ }
+
+ public void setIdOrganisation(Long idOrganisation) {
+ this.idOrganisation = idOrganisation;
+ }
+
+ @Id
+ @Column( name = "id_organisation", nullable = false )
+ public Long getIdOrganisation() {
+ return idOrganisation;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Column( name = "name", nullable = false, length = 40 )
+ public String getName() {
+ return name;
+ }
+
+ public void setOrganisationUsers(Set<OrganisationUser> organisationUsers) {
+ this.organisationUsers = organisationUsers;
+ }
+
+ @OneToMany( mappedBy = "organisation",
+ fetch = FetchType.LAZY,
+ cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
+ @OrderBy( value = "firstName" )
+ public Set<OrganisationUser> getOrganisationUsers() {
+ return organisationUsers;
+ }
+
+}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java 2007-01-16
23:24:17 UTC (rev 11051)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OrganisationUser.java 2007-01-17
00:40:54 UTC (rev 11052)
@@ -0,0 +1,46 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@PrimaryKeyJoinColumn( name = "id_organisation_user" )
+@Table( name = "ORGANISATION_USER" )
+public class OrganisationUser extends Person implements Serializable {
+
+ private String someText;
+ private Organisation organisation;
+
+ public OrganisationUser() {
+ }
+
+ public void setSomeText(String someText) {
+ this.someText = someText;
+ }
+
+ @Column( name = "some_text", nullable=true,length=1024)
+ public String getSomeText() {
+ return someText;
+ }
+
+ public void setOrganisation(Organisation organisation) {
+ this.organisation = organisation;
+ }
+
+ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
+ @JoinColumn( name = "fk_id_organisation", nullable = false )
+ public Organisation getOrganisation() {
+ return organisation;
+ }
+
+}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java 2007-01-16
23:24:17 UTC (rev 11051)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Person.java 2007-01-17
00:40:54 UTC (rev 11052)
@@ -0,0 +1,55 @@
+//$Id: $
+package org.hibernate.test.annotations.onetomany;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.InheritanceType;
+import javax.persistence.Inheritance;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Inheritance( strategy = InheritanceType.JOINED )
+@Table( name = "PERSON_Orderby" )
+public class Person implements Serializable {
+
+ private Long idPerson;
+ private String firstName, lastName;
+
+ public Person() {
+ }
+
+ public void setIdPerson(Long idPerson) {
+ this.idPerson = idPerson;
+ }
+
+ @Id
+ @Column( name = "id_person", nullable = false )
+ public Long getIdPerson() {
+ return idPerson;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Column( name = "first_name", length = 40, nullable = false )
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Column( name = "last_name", length = 40, nullable = false )
+ public String getLastName() {
+ return lastName;
+ }
+
+}
+