[Hibernate-JIRA] Created: (ANN-786) Filters on collections are ignored
by Eric Ford (JIRA)
Filters on collections are ignored
----------------------------------
Key: ANN-786
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-786
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.2.0.ga
Environment: Hibernate 3.2; MySql 5.0.51a; Java 1.6
Stand-alone app - no server
Reporter: Eric Ford
I have two classes: Topic and Narrative. A topic has one-to-many narratives. I want to impose a filter such that only narratives with a particular state value are returned when I look up a topic.
@Entity
public class Topic
{
//unrelated attributes not shown
private Set<Narrative> narratives = new HashSet<Narrative>();
@OneToMany(mappedBy="topic")
@Filter(name="byState", condition=":state = state")
public Set<Narrative> getNarratives()
{
return narratives;
}
public void setNarratives(Set<Narrative> narratives)
{
this.narratives = narratives;
}
}
@Entity
@FilterDef(name="byState", defaultCondition=":state = state",
parameters=@ParamDef(name="state",type="string"))
@Filter(name="byState", condition=":state = state")
public class Narrative
{
private String content = "";
private String state = "";
private Topic topic = null;
//getters and setters not shown
}
@Test
public void FindSystemById(){
//for this test, the indicated topic has two narratives,
//one is "published" and the other is "draft"
session.enableFilter("byState").setParameter("state", "published");
Topic result = null;
result = TopicDao.findById(new Long(1), noLock); //
assertNotNull(result); //this always passes, as expected
System.out.println(result.getNarratives().size(); //this always returns 2
assertTrue(result.getNarratives().size() == 1); //this always fails, obviously
}
The sql code does not show the filter being applied when fetching the collection.
I've tried variations including adding the @Filter annotation to the getNarratives() method only and adding the @Filter annotation to the Narrative class only. I've also tried putting the @FilterDef annotation on the Topic class instead of the Narrative class. None of these variations has given the desired result of only one narrative returned from the getNarratives() method. I am coding with Java 1.6, Hibernate 3.2, and MySql 5.0.51a using Eclipse 3.4 and testing with JUnit 4.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (ANN-794) Polymorphic query on abstract function
by radu (JIRA)
Polymorphic query on abstract function
--------------------------------------
Key: ANN-794
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-794
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.0.ga
Reporter: radu
Priority: Blocker
I have the following classes adnnotated with hibernate:
<pre><code>
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Symbol
implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@AccessType("property")
public abstract String getCode();
@AccessType("property")
public abstract void setCode(String code);
}
@javax.persistence.Entity
@AttributeOverride( name="code", column = @Column(name="field1") )
public class Child1 extends Symbol {
@Basic
@Column(nullable = false)
private String field1;
@AccessType("property")
public String getCode() {
return getField1();
}
@AccessType("property")
public void setCode(String code) {
setField1(code);
}
public void setField1(String field1) {
this.field1 = field1;
}
public String getField1() {
return field1;
}
}
@javax.persistence.Entity
@AttributeOverride( name="code", column = @Column(name="field2") )
public class Child2 extends Symbol {
@Basic
@Column(nullable = false)
private String field2;
@AccessType("property")
public String getCode() {
return getField2();
}
@AccessType("property")
public void setCode(String code) {
setField1(code);
}
public void setField1(String field2) {
this.field2 = field2;
}
public String getField2() {
return field2;
}
}
</code></pre>
As objectual rules about polymorphisms the following query should be valid and to retrieve correct field value:
session.createQuery("from Symbol s where s.code = :code");
but it give me the error:
org.hibernate.QueryException: could not resolve property: code of: ...
Please give some advices how to work around this problem if this situation does not follow hibernate concept or JPA specs and is not possible to implement it.
Idea is that it should be possible to work at hight level without changing database or existing classes.
Thanks
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 2 months
[Hibernate-JIRA] Created: (HHH-4095) bug in org.hibernate.Hibernate.createBlob( InputStream in )
by Stephan Schröder (JIRA)
bug in org.hibernate.Hibernate.createBlob( InputStream in )
-----------------------------------------------------------
Key: HHH-4095
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4095
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: (doesn't matter because ii's just a plain wrong usage of the InputStream.available-mehtode but anyway:) Hibernate. 3.3.2, Hsqldb1.8
Reporter: Stephan Schröder
Priority: Minor
The implementation of org.hibernate.Hibernate.createBlob( InputStream in ) looks like this
public static Blob createBlob(InputStream stream) throws IOException {
return new SerializableBlob( new BlobImpl( stream, stream.available() ) );
}
The second parameter here is supposed to be the length of the inputstream. The problem is that stream.available() doesn't return the length of the inputstream. That's explicitly noted in the Java-API (http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available):
"Note that while some implementations of InputStream will return the total number of bytes in the stream (on calling available() ), many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream."
This is the source of my problem, only the first available bytes are read out of the inputstream. While the workaround for me is to simply call org.hibernate.Hibernate.createBlob( InputStream in,int length ), the misuse of stream.available() in Hibernate.createBlob( InputStream in ) remains to be resolved.
Solution: the only way to get the length of an InputStream ist to read it completly, if you don't want to do that Hibernate.createBlob( InputStream i ) should be removed.
(By the way, why is length of type int? java.io.File.length() and java.sql.Blob.length() are of type long, so length should be of type long as well).
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 3 months
[Hibernate-JIRA] Created: (HHH-2967) Cast to date in Formula still doesn't work
by Frederic Leitenberger (JIRA)
Cast to date in Formula still doesn't work
------------------------------------------
Key: HHH-2967
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2967
Project: Hibernate3
Issue Type: Bug
Components: query-criteria, query-hql, query-sql
Affects Versions: 3.2.5
Environment: Hibernate-Version: 3.2.5.ga
Oracle 9i/10g
Reporter: Frederic Leitenberger
Priority: Minor
Similar to HHH-473.
Oracle 10g supports trunc(TS). (TS is a timestamp)
Oracle 9i only supports trunc(cast(TS as date)) [and 10g supports this still too].
Therefore i need to add the cast to the Forumla.
@Basic
@Column(nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
@Formula(value = "trunc(cast(created as date))")
public Date getDate() {
return date
}
public void setDate(Date date {
this.date= date
}
This results in the following query:
select
eventlog0_.id as id9_0_,
eventlog0_.created as created9_0_,
.........
trunc(cast(eventlog0_.created as eventlog0_.date)) as formula6_0_
from
ICCS6.EventLog eventlog0_
where
eventlog0_.id=?
The alias in front of "date" is obviously misplaced there.
I also tried renaming the formula (since it was called "date"), but this didn't change the result.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 3 months