[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2988) UnionSubclassEntityPersister.generateSubquery() does not use column.getQuotedName()

benoit heinrich (JIRA) noreply at atlassian.com
Tue Dec 4 03:59:56 EST 2007


UnionSubclassEntityPersister.generateSubquery() does not use column.getQuotedName()
-----------------------------------------------------------------------------------

                 Key: HHH-2988
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2988
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.5
            Reporter: benoit heinrich
            Priority: Critical


Hi all,

I'm new to hibernate and I'm trying to use the Inheritance strategy TABLE_PER_CLASS with a Postgres database.
The postgres database contains tables and column with upper cases names (names must be quoted).
In the entity I used the back-quote ` sign to quote the table names and column names.
All basic requests work but when I have an association going to the virtual parent table then I got an error due to the fact that the Union subclass entity persister does not quote the column names inside the sub query.

I've locate the problem and I think it occurs here:
org.hibernate.persister.entity.UnionSubclassEntityPersister.java   (svn rev. 11398)
line 395 ------------------------------------------------------------------------------------------------
                                while ( citer.hasNext() ) {
                                        Column col = (Column) citer.next();
                                        if ( !table.containsColumn(col) ) {
                                                int sqlType = col.getSqlTypeCode(mapping);
                                                buf.append( dialect.getSelectClauseNullString(sqlType) )
                                                        .append(" as ");
                                        }
                                        buf.append( col.getName() );
                                        buf.append(", ");
But should be ------------------------------------------------------------------------------------------------
                                        buf.append( col.getQuotedName() );



Here is an example to test:

Item.java:
---------------------------------
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Item implements java.io.Serializable {
	private long id;
	private Container parent;
/** getter / setter */
 
	@Id
	@Column(name = "`ID`", unique = true, nullable = false, insertable = true, updatable = true)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "item_id_seq_generator")
	@SequenceGenerator(name="item_id_seq_generator", sequenceName="item_id_seq", allocationSize=1)
	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "`ParentID`", unique = false, nullable = true, insertable = true, updatable = true)
	public Container getParent() {
		return this.parent;
	}

	public void setParent(Container parent) {
		this.parent = parent;
	}
}

Container.java
---------------------------------
@Entity
@Table(name = "`CoNTaiNeR`")
public class Container extends Item {
	private Set<Item> items = new HashSet<Item>(0);

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "parent", targetEntity = Item.class)
	public Set<Item> getItems() {
		return this.items;
	}

	public void setItems(Set<Item> items) {
		this.items = items;
	}
}

SimpleItem.java
---------------------------------
@Entity
@Table(name = "`SimpleItem`")
public class SimpleItem extends Item {
	/*...*/
}


So when you try to get the Container.getItems() then it generates the wrong query.



Cheers,
/Benoit

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list