[Hibernate-JIRA] Created: (HHH-3807) Adding a restriction to a many-to-one entity in Criteria query causes Join fetching
by Jonathan Gordon (JIRA)
Adding a restriction to a many-to-one entity in Criteria query causes Join fetching
-----------------------------------------------------------------------------------
Key: HHH-3807
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3807
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1GA
Sql Server 2005
Reporter: Jonathan Gordon
Priority: Minor
When performing a criteria query that includes a restriction on a many-to-one entity, the associated entity is fetched eagerly, as if FetchMode were set to "JOIN". Explicitly setting the FetchMode to "SELECT" does not override this behavior.
For instance, this criteria query:
Criteria criteria = persistenceService.getCriteria(MailingParcel.class)
.createAlias("mailingCampaign", "mc")
.add(Restrictions.ge("mc.id", 1))
.setMaxResults(10);
Yields the following sql:
select
top 10 this_.ID as ID17_1_,
this_.KEYCODE as KEYCODE17_1_,
this_.CAMPAIGN_ID as CAMPAIGN3_17_1_,
this_.MAILING_LIST_MAILING_ID as MAILING4_17_1_,
this_.COUNTRY_LE_ID as COUNTRY5_17_1_,
this_.MATCH_ADDRESS as MATCH6_17_1_,
this_.ADDRESS as ADDRESS17_1_,
this_.MATCH_NAME as MATCH8_17_1_,
this_.FIRST_NAME as FIRST9_17_1_,
this_.LAST_NAME as LAST10_17_1_,
this_.ZIP_CODE asZIP11_17_1_,
this_.CITY as CITY17_1_,
this_.STATE as STATE17_1_,
this_.COMPANY as COMPANY17_1_,
mc1_.ID as ID6_0_,
mc1_.NOTE as NOTE6_0_,
mc1_.NAME as NAME6_0_,
mc1_.DATE_CREATED as DATE5_6_0_,
mc1_.DATE_MODIFIED as DATE6_6_0_,
mc1_.START_DATE as START7_6_0_,
mc1_.SOURCE_FILE_NAME as SOURCE8_6_0_,
mc1_.ORDINAL as ORDINAL6_0_,
mc1_.KEYCODE_SUFFIX as KEYCODE10_6_0_,
mc1_.MATCH_CATALOG_ID as MATCH11_6_0_,
mc1_.ADDRESS_IMPORT_DATE as ADDRESS12_6_0_
from MATCH_MAILING_CAMPAIGN this_
inner join MATCH_CAMPAIGN_INFO mc1_ on this_.CAMPAIGN_ID=mc1_.ID
where mc1_.ID>=1
However, removing the restriction yields the following sql:
select
top 10 this_.ID as ID17_0_,
this_.KEYCODE as KEYCODE17_0_,
this_.CAMPAIGN_ID as CAMPAIGN3_17_0_,
this_.MAILING_LIST_MAILING_ID as MAILING4_17_0_,
this_.COUNTRY_LE_ID as COUNTRY5_17_0_,
this_.MATCH_ADDRESS as MATCH6_17_0_,
this_.ADDRESS as ADDRESS17_0_,
this_.MATCH_NAME as MATCH8_17_0_,
this_.FIRST_NAME as FIRST9_17_0_,
this_.LAST_NAME as LAST10_17_0_,
this_.ZIP_CODE as ZIP11_17_0_,
this_.CITY as CITY17_0_,
this_.STATE as STATE17_0_,
this_.COMPANY as COMPANY17_0_
from MATCH_MAILING_CAMPAIGN this_
Performing the original query in its HQL analog does not have this problem.
--
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
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-2544) Create the EntityPersisters in order based on Inheritance hierarchy
by Shawn Clowater (JIRA)
Create the EntityPersisters in order based on Inheritance hierarchy
-------------------------------------------------------------------
Key: HHH-2544
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2544
Project: Hibernate3
Issue Type: New Feature
Components: core
Affects Versions: 3.2.3
Reporter: Shawn Clowater
Priority: Minor
I have a bit of what might seem to be an odd request.
I had run into a scenario where filters on my mappings that were part of a Single Table hierarchy were not getting into the configuration and it turned out it was based on the order that the EntityPersisters were being created as we've doing some minor magic with Custom EntityPersisters for filters.
In our case we have a filter template where the filter is pretty much the same for each class that implements it except for the table and key name used in the filter.
So, rather than define this annotation everywhere (we had previously been using xdoclet to generate it for the hbm mappings) we pushed the logic into a Custom Persister.
So, essentially as it is building the EntityPersister we intercept the PersistentClass before it calls the super() constructor and add our required filters on the PersistantClass (in its FilterMap) before it gets passed up. This is done like this because by the time it gets to the AbstractEntityPersister's constructor it uses the filterMap to construct the FilterHelper and then you're done as you have no access to change that after it is built.
So, in the Inheritance case any subclasses that are built before the main root class will not have the filters that we inject during the construction of our Custom Entity Persisters. I have temporarily worked around it by changing the Subclasses getFilterMap() method to not only return the filters from the Parent class but also from the class itself. Now, normally you can't define the filter on the subclass but I can through the persister.
What I'd like to do is:
Make the persister class for the subclasses a 'standard' persister that doesn't add any filters to the subclass.
Still have my root class' entity persister adding the filters.
But have the Entity Persisters built in hierarchal order in the SessionFactoryImpl.
Since they are being built in any given order right now, I can't see an issue with providing some order to them, something like the AnnotationBinder does.
--
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
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-3574) ANY mapping ignores lazy="false"
by Manuel Dominguez Sarmiento (JIRA)
ANY mapping ignores lazy="false"
--------------------------------
Key: HHH-3574
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3574
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Reporter: Manuel Dominguez Sarmiento
We have a use case for eager fetching of an <any> association. The DTD accepts lazy="false|true", however at runtime it doesn't make any difference.
Digging deeper, we see that org.hibernate.mapping.Any does not have a lazy property, furthermore, it does not extend Fetchable. This explains why it will not work as expected.
There are two possible resolutions:
1) Implement eager fetching for <any> associations, unless there is some technical difficulty in doing so. Of course lazy fetching won't be possible using joins because of the nature of this type of associations, however it should be simple enough with a second select. This means that the XML config should handle lazy="false|true" but not fetch="join|select|subselect|etc"
2) Fix the DTD in case this can't be done to avoid confusion (less desirable).
--
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
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-3008) Cascade delete does not work with unidirectional @OneToMany and @JoinTable
by Daniel Dyer (JIRA)
Cascade delete does not work with unidirectional @OneToMany and @JoinTable
--------------------------------------------------------------------------
Key: HHH-3008
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3008
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.5
Environment: Standalone entity manager (JavaSE 5.0).
H2 database.
Reporter: Daniel Dyer
A unidirectional one-to-many relationship defined as follows:
public class Owner
{
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "owner_element",
joinColumns = @JoinColumn(name = "owner_id",
nullable = false,
updatable = false),
inverseJoinColumns = @JoinColumn(name = "element_id",
nullable = false,
updatable = false))
private List<Element> elements;
// ...
}
Attempting to delete an instance of Owner should also delete all associated instances of Element. Instead I get the following error:
SEVERE: Referential integrity constraint violation: FK56BBF9C487E817D: PUBLIC.OWNER_ELEMENT FOREIGN KEY(OWNER_ID) REFERENCES PUBLIC.OWNER(ID) [23003-63]
This is because Hibernate attempts to delete the Owner row without first removing the rows from the join table.
--
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
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-4073) discriminator formula creates problem in hibernate envers
by Saravana Kumar (JIRA)
discriminator formula creates problem in hibernate envers
---------------------------------------------------------
Key: HHH-4073
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4073
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.3.x
Environment: hibernate-3.3.x, envers-1.2.1.ga-hibernate-3.3.jar (Oracle 10g or HSQLDB)
Reporter: Saravana Kumar
I map my classes using Single Table per class hierarchy as below
@Entity
@DiscriminatorFormula ("(select t.c_type from t_type t where t.c_id = c_type)")
@Audited
public class Attribute...{
...
}
or
<discriminator type="string">
<formula>(select t.c_type from t_type t where t.c_id = c_type)</formula>
</discriminator>
When I use envers
I get the follwoing error
Caused by: java.lang.ClassCastException: org.hibernate.mapping.Formula
at org.hibernate.envers.configuration.metadata.MetadataTools.addColumns(MetadataTools.java:154)
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateMappingData(AuditMetadataGenerator.java:263)
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:345)
at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:87)
at org.hibernate.envers.configuration.AuditConfiguration.(AuditConfiguration.java:86)
at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:260)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
When I tried to debug the problem
(AuditMetadataGenerator.java:263) has
260: // Checking if there is a discriminator column
261: if (hasDiscriminator) {
262: Element discriminator_element = class_mapping.addElement("discriminator");
263: MetadataTools.addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator());
264: discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
265: }
(MetadataTools.java:154) has
152: public static void addColumns(Element any_mapping, Iterator<Column> columns) {
153: while (columns.hasNext()) {
154: Column column = columns.next();
155: addColumn(any_mapping, column.getName(), column.getLength(), column.getScale(), column.getPrecision(),
156: column.getSqlType());
157: }
158: }
I see that there is nothing to handle Formula :-(
Can you investigate?
--
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
13 years, 9 months