[Hibernate-JIRA] Created: (HHH-3414) fetch profiles
by Steve Ebersole (JIRA)
fetch profiles
--------------
Key: HHH-3414
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3414
Project: Hibernate3
Issue Type: New Feature
Components: core, metamodel
Reporter: Steve Ebersole
Assignee: Steve Ebersole
Fix For: 3.4
The concept of fetch profiles as we are discussing here is basically to allow users to dynamically affect the mapped fetching strategy for associations at runtime.
Consider the following example:
<class name="Person">
...
<set name="addresses" lazy="true" fetch="subselect" ...>
...
</set>
</class>
<class name="Address">
...
</class>
This follows the normal recommendation to map associations as lazy and use a dynamic fetching strategy (ala HQL/Criteria) to modify this lazy behavior at runtime.
The fetaure discussed here would allow the same behavior for loading as well:
<hibernate-mapping>
<fetch-profile name="person-details">
<fetch path="Person.addresses" style="join"/>
</fetch-profile>
</hibernate-mapping>
Or:
<hibernate-mapping>
<class name="Person">
...
<fetch-profile name="person-details">
<fetch path="addresses" style="join"/>
</fetch-profile>
<set name="addresses" lazy="true" fetch="subselect" ...>
...
</set>
</class>
</hibernate-mapping>
Now, doing:
session.enableFetchProfile( "person-details" ).get( Person.class, 1 )...
will load Person#1 as well as their addresses in a single joined query.
--
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
12 years, 11 months
[Hibernate-JIRA] Created: (ANN-721) ManyToOne Persisting Cascade in Embeddable
by Endre Jeges (JIRA)
ManyToOne Persisting Cascade in Embeddable
------------------------------------------
Key: ANN-721
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-721
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.1.GA
Environment: Java version:
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
Oracle Version:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
"CORE 9.2.0.8.0 Production"
TNS for Linux: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
hibernate: 3.2.6.ga
hibernate-annotations: 3.3.1.ga
hibernate-commons-annotations: 3.3.0.ga
hibernate-entitymanager: 3.3.1.ga
Reporter: Endre Jeges
Attachments: pairTest.zip
Hello,
I have found something that is a bit strange. For @ManyToOne association properties in an @Embeddable class the cascade PERSIST, SAVE-UPDATE option is not working well (not sure for the other cascade types), if the entities associated with ManyToOne are transient. I have created a unit test to check it and I have it attached to this issue. It is a maven2 project, and needs Oracle to run it. If I save the associated entites, then everything works fine, also the data structure is created well.
I have checked the forums and found similar problems, maybe they can help more then my post:
http://forum.hibernate.org/viewtopic.php?t=965238
http://forum.hibernate.org/viewtopic.php?t=976534
http://forum.hibernate.org/viewtopic.php?t=978112
http://forum.hibernate.org/viewtopic.php?t=978138
http://forum.hibernate.org/viewtopic.php?t=983766
http://forum.hibernate.org/viewtopic.php?t=983780
http://forum.hibernate.org/viewtopic.php?t=983868
Details:
@Entity
class CodedPairHolder {
@Id
private Long id;
@Column(name = "CODE", nullable = false, unique = true, updatable = false, length = 256)
private String code;
@CollectionOfElements
@JoinTable(name = "CODED_PAIR_HOLDER_PAIR_SET", joinColumns = @JoinColumn(name = "CODED_PAIR_HOLDER_ID"))
private final Set<PersonPair> pairs = new HashSet<PersonPair>(0);
........ constructors getters equals hashCode
}
@Embeddable
class PersonPair {
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@Cascade( { org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.REFRESH,
org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.REPLICATE, org.hibernate.annotations.CascadeType.EVICT })
@JoinColumn(name = "LEFT_PERSON_ID", nullable = false, updatable = false)
private Person left;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@Cascade( { org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.REFRESH,
org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.REPLICATE, org.hibernate.annotations.CascadeType.EVICT })
@JoinColumn(name = "RIGHT_PERSON_ID", nullable = false, updatable = false)
private Person right;
........ constructors getters equals hashCode
}
@Entity
class Person {
@Id
private Long id;
@Column(name = "NAME", nullable = false, unique = true, updatable = false, length = 256)
private String name;
........ constructors getters equals hashCode
}
The error message is:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Person
Regards,
jeges
--
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
12 years, 11 months
[Hibernate-JIRA] Created: (HHH-2738) Eager fetch support for StatelessSession
by Christian Bauer (JIRA)
Eager fetch support for StatelessSession
----------------------------------------
Key: HHH-2738
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2738
Project: Hibernate3
Issue Type: Task
Components: core
Reporter: Christian Bauer
class Node {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PARENT_NODE_ID", nullable = true)
protected Node parent;
}
StatelessSession ss = getStatelessSession();
Node node = (Node) ss.get(Node.class, nodeId);
[testng] org.hibernate.AssertionFailure: possible non-threadsafe access to the session
[testng] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:100)
[testng] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
[testng] at org.hibernate.loader.Loader.doQuery(Loader.java:729)
[testng] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
[testng] at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
[testng] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
[testng] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
[testng] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3042)
[testng] at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:158)
[testng] at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:153)
[testng] at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:145)
--
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
12 years, 11 months
[Hibernate-JIRA] Created: (HHH-3655) Select Query Using JPA and Static Inner Class
by Caine Lai (JIRA)
Select Query Using JPA and Static Inner Class
---------------------------------------------
Key: HHH-3655
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3655
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.1
Environment: Hibernate Version 3.3.1 GA, using JPA. MySQL DB.
Reporter: Caine Lai
Attachments: HibernateStaticInnerClassBug.zip
I want to collect some statistics using JPA and return them all as a value object to my web tier. In my value object I have a static inner class I would like to use for the JPA query.
My Class:
public class GeneralVendorStatsVO {
private List<StatusCounts> statusCounts = new ArrayList<StatusCounts>();
/**
* Inner class for holding status counts for vendors.
*/
public static class StatusCounts {
private UserStatus status;
private Long count;
public StatusCounts(UserStatus status, Long count) {
this.status = status;
this.count = count;
}
public UserStatus getStatus() { return status; }
public void setStatus(UserStatus status) { this.status = status; }
public Long getCount() { return count; }
public void setCount(Long count) { this.count = count; }
}
// ********************** Accessor Methods ********************** //
public List<StatusCounts> getStatusCounts() { return statusCounts; }
public void setStatusCounts(List<StatusCounts> statusCounts) { this.statusCounts = statusCounts; }
}
And here is the method I am trying to execute:
public GeneralVendorStatsVO getGeneralVendorStats() {
GeneralVendorStatsVO vo = new GeneralVendorStatsVO();
// Get the status counts.
String queryString = "SELECT new vo.stats.vendor.GeneralVendorStatsVO.StatusCounts(user.status, count(user)) FROM User user GROUP BY user.status";
Query query = this.em.createQuery(queryString);
List<GeneralVendorStatsVO.StatusCounts> statusCounts = query.getResultList();
vo.setStatusCounts(statusCounts);
for (GeneralVendorStatsVO.StatusCounts entry : statusCounts) {
log.debug("Status: " + entry.getStatus()+ "Count: " + entry.getCount());
}
return vo;
}
The error:
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate class [vo.stats.vendor.GeneralVendorStatsVO.StatusCounts]
I don't know why this would not work, when I can do:
new GeneralVendorStatsVO.StatusCounts(UserStatus.APPROVED, 200L)
I was told I should open an issue because it seems like a bug. More info here: http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78...
--
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
12 years, 11 months
[Hibernate-JIRA] Created: (HHH-2052) org.hibernate.pretty.MessageHelper.collectionInfoString tries to cast wrong object to String, causes ClassCastException
by Tree 'Huggy Bear' Hugger (JIRA)
org.hibernate.pretty.MessageHelper.collectionInfoString tries to cast wrong object to String, causes ClassCastException
-----------------------------------------------------------------------------------------------------------------------
Key: HHH-2052
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052
Project: Hibernate3
Type: Bug
Reporter: Tree 'Huggy Bear' Hugger
Attachments: bugtest.zip
Debug level logging attempted by MessageHelper falls over when constructing a loggable string for a mapped collection on the main entity.
Following the code in the stacktrace, I can see that MessageHelper expects the parent key for the collection relationship to be the primary key, but it is mapped to another field of a different type via a property-ref. Hence the ClassCastException below.
The work around is to set logging to INFO or higher.
I have also attached a pared-down zip with the maven 2 project containing the mappings and the unit test which fails.
The following JIRA issue may be the same thing:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-298
The following messages on the Hib forum demonstrate other interest in this issue:
http://forum.hibernate.org/viewtopic.php?t=949913
http://forum.hibernate.org/viewtopic.php?t=956778
http://forum.hibernate.org/viewtopic.php?t=962471
java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:972)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:452)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:446)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:440)
at com.nomadsoft.cortex.infrastructure.hibernate.HibernateCountryRepository.getById(HibernateCountryRepository.java:26)
at com.nomadsoft.cortex.domain.country.basic.BasicCountryService.getCountry(BasicCountryService.java:34)
etc etc
--
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
12 years, 11 months
[Hibernate-JIRA] Created: (HHH-3383) QueryKey is storing references to entities instead of identifiers
by Manuel Dominguez Sarmiento (JIRA)
QueryKey is storing references to entities instead of identifiers
-----------------------------------------------------------------
Key: HHH-3383
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3383
Project: Hibernate3
Issue Type: Improvement
Components: caching (L2)
Affects Versions: 3.3.0.CR1
Environment: ehcache 1.5.0b2
Reporter: Manuel Dominguez Sarmiento
Context: query caching
Hibernate is storing full entity references when building QueryKeys and the query has restrictions which reference entities. This happens either with Criteria or HQL queries.
Although this is not incorrect, when the referenced entities reference in turn "heavy" object graphs, this causes a very significant memory usage increase, since references to detached entities will remain in the cache. This is even more evident when using disk persistence with ehcache, since the full object graphs are serialized to disk.
This could be easily improved (correct me if I'm wrong) by storing ONLY entity identifiers in the QueryKey instead of full entities, since all the query really needs is the identifier property. The memory usage would decrease dramatically.
So far the workaround we've found is explicitly using restrictions that reference identifiers instead of properties in HQL queries, however this is not particularly elegant, and still leaves open the issue with Criteria queries. The same cannot be done without criteria.createCriteria() which generates an unnecessary join in most cases.
--
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
12 years, 11 months