[Hibernate-JIRA] Created: (HHH-3174) Session/SessionFactory should be extendable or provide a mechanism to store session level data in it
by Will Hoover (JIRA)
Session/SessionFactory should be extendable or provide a mechanism to store session level data in it
----------------------------------------------------------------------------------------------------
Key: HHH-3174
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3174
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.2.6
Environment: N/A
Reporter: Will Hoover
ISSUE:
Most frameworks that have a concept of a session that allow customization of that session either by providing a means to extend it or by providing a mechanism to store data in it. There are many cases where storing Session level data makes sense.
EXAMPLE USE CASE:
For instance, if capture of the actual user that is using the Session is needed it makes sense that it resides as an attribute of the current Session that is being used by that user. An example of this would be an Audit Log/Trail that needs to capture who/what is using the current Session. The Hibernate documentation proposes to use an Interceptor for this by setting the user within it, but this is not the proper location to capture this data especially if multiple Interceptors are needed (which cannot be done currently- i.e. an audit log Interceptor and a security Interceptor- using listeners can work, but require the user to be set on each listener being used). If an Interceptor or listener were to hold the user we would lose the feature of obtaining the user if we didn't need the interceptor/listener in a project. It makes more sense to add the user to the session because it will be commonly used throughout the Session life-cycle.
PROPOSED RESOLUTION OPTION 1 (add simple HashMap in the session):
If the session contained a simple HashMap it would accommodate 99% of use cases where a session level attribute is needed.
PROPOSED RESOLUTION OPTION 2 (allow extension of Session/SessionFactory):
Currently the org.hibernate.Configuration has a method to buildSessionFactory(...) that instantiates a new instance of org.hibernate.impl.SessionFactoryImpl preventing the SessionFactory implementation from being defined. The org.hibernate.impl.SessionFactoryImpl also has a method to openSession(...) that instantiates a new instance of org.hibernate.impl.SessionImpl preventing the Session implementation from being defined. A possible solution would be to allow the implementation to be passed/proxy.
--
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
16 years, 9 months
[Hibernate-JIRA] Commented: (HHH-1574) AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids
by Dylan Schell (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574?page=c... ]
Dylan Schell commented on HHH-1574:
-----------------------------------
Still present in 3.2.5.ga
> AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids
> --------------------------------------------------------------------------------------
>
> Key: HHH-1574
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.1.2
> Reporter: Alex Burgel
> Attachments: resolveentity.patch, resolveentity32.patch, testcase.zip
>
>
> i just upgraded from 3.0.5 to 3.1.2, and i started seeing this problem. i'm not exactly sure where the bug is here, but this is what i'm seeing:
> i have a class, Subscription, which has a natural-id of class Subscriber and Edition (excerpts of relevant mapping files below).
> when Subscription is unloaded, if i make a change, then commit the session, i see this exception:
> HibernateException: immutable natural identifier of an instance of Subscription was altered
> this gets thrown from DefaultFlushEntityEventListener.checkNaturalId() line 80.
> i traced through that method, this is what happens:
> 1. in checkNaturalId, loaded == null , so getNaturalIdSnapshot() is called
> 2. this ends up generating some sql that selects the SubscriptionId and EditionId from the Subscription row.
> 3. the sql is generated in AbstractEntityPersister.getNaturalIdentifierSnapshot(), which calls hydrate for each returned column of the natural-id,
> 4. but hydrate only returns the id, instead of the actual entity
> 5. so this array of ids (instead of entities) ends up back in DefaultFlushEntityEventListener.checkNaturalId() as 'loaded', which gets compared to 'current'
> the trouble is that 'current' contains the entities, but 'loaded' only contains the ids of those entites, so the natural-id check fails, and i get the exception.
> this only happens when 'loaded' is null in checkNaturalId().
> the javadocs for hydrate say you have to call "resolve" afterwards... this isn't being done, so maybe thats the fix. if the natural-id is not just simple properties, then resolve should also be called.
> <class name="Subscription" table="Subscriptions" batch-size="10">
> <id name="id" column="Id" type="int"><generator class="native" /></id>
> <natural-id>
> <many-to-one name="subscriber" class="Subscriber" column="SubscriberId" />
> <many-to-one name="edition" class="Edition" column="EditionId" />
> </natural-id>
> ....
> </class>
> <class name="Subscriber" table="Subscriber">
> <id name="id" column="id" type="int"><generator class="native" /></id>
> <map name="subscriptions" inverse="true" cascade="all,delete-orphan" batch-size="10">
> <key column="SubscriberId" />
> <map-key-many-to-many column="EditionId" class="Edition" />
> <one-to-many class="Subscription" />
> </map>
> </class>
--
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
16 years, 9 months
[Hibernate-JIRA] Created: (HHH-3172) There should be a way to add a Serializable object that represents the user that is using the current session
by Will Hoover (JIRA)
There should be a way to add a Serializable object that represents the user that is using the current session
-------------------------------------------------------------------------------------------------------------
Key: HHH-3172
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3172
Project: Hibernate3
Issue Type: Bug
Components: core
Environment: N/A
Reporter: Will Hoover
There should be a way to add a Serializable object that represents the user that is using the current session. The only way to do this now is:
Interceptor interceptor = new MyInterceptor();
Session session = factory.openSession(interceptor);
interceptor.setSession(session);
interceptor.setUserId(user.getId());
Should be:
Serializable user = ...
Session session = factory.openSession(user);
An alternative and more flexible solution would be to allow the session to be customized. Currently the org.hibernate.Configuration instantiates the factory implementation (if this is done- not sure why it is interfaced to begin with). This is repeated in session factory implementation as well:
public SessionFactory buildSessionFactory() throws HibernateException {
...
// why not overload the build method and allow impl to be passed if desired?
return new SessionFactoryImpl(
this,
mapping,
settings,
getInitializedEventListeners()
);
}
private SessionImpl openSession(
Connection connection,
boolean autoClose,
long timestamp,
Interceptor sessionLocalInterceptor
) {
// why not overload the open session method and allow impl to be passed if desired?
return new SessionImpl(
connection,
this,
autoClose,
timestamp,
sessionLocalInterceptor == null ? interceptor : sessionLocalInterceptor,
settings.getDefaultEntityMode(),
settings.isFlushBeforeCompletionEnabled(),
settings.isAutoCloseSessionEnabled(),
settings.getConnectionReleaseMode()
);
}
--
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
16 years, 9 months
[Hibernate-JIRA] Created: (HHH-3110) JTATransaction could not find UserTransaction in JNDI when working with JOTM
by Felix von Delius (JIRA)
JTATransaction could not find UserTransaction in JNDI when working with JOTM
----------------------------------------------------------------------------
Key: HHH-3110
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3110
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6, Oracle9i, jotm-2.0.10
Reporter: Felix von Delius
Priority: Critical
In our local (out-of-container) environment, we use JTA with JOTM as the JTA implementation.
It seems that the fix for HHH-1956 has this side effect, since I build a patched version of Hibernate-3.2.6 with the lazy initialization of hibernateTransaction commented out (lines 171-173 in JDBCContext.java).
Here is the relevant part of the stacktrace caused by the problem:
[ID:KxMaQ USER:\OPTIMMOSYS] 15:27:04,107 ERROR [JTATransaction] Could not find UserTransaction in JNDI
javax.naming.NameNotFoundException
at org.objectweb.carol.jndi.enc.java.CompNamingContext.lookupCtx(CompNamingContext.java:689)
at org.objectweb.carol.jndi.enc.java.CompNamingContext.lookup(CompNamingContext.java:179)
at org.objectweb.carol.jndi.enc.java.JavaURLContext.lookup(JavaURLContext.java:138)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:57)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:172)
at org.hibernate.jdbc.JDBCContext.<init>(JDBCContext.java:76)
at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:213)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:473)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:497)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:505)
at com.ing.diba.mws.tcore.persistence.HibernateSessionSourceImpl.createPersistenceProvider(HibernateSessionSourceImpl.java:45)
Our configuration in this case contains:
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JOTMTransactionManagerLookup
--
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
16 years, 9 months
[Hibernate-JIRA] Updated: (HBX-446) one-to-many relation with not-null attribute on key element
by Max Rydahl Andersen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-446?page=co... ]
Max Rydahl Andersen updated HBX-446:
------------------------------------
Fix Version/s: (was: 3.2.1)
3.2.2
> one-to-many relation with not-null attribute on key element
> -----------------------------------------------------------
>
> Key: HBX-446
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-446
> Project: Hibernate Tools
> Issue Type: Bug
> Components: hbm2java
> Environment: 3.x
> Reporter: Sreeram Katta
> Priority: Critical
> Fix For: 3.2.2
>
>
> one-to-many relation with not-null attribute on key element is throwing below error when I run the hbm2java tool. I have a base class with a joined-subclass and the joined subclass has one-to-many relationship with another class. The one-to-many uses a list. When I specify not-null attribute on the key element in the relationship I get the below error. If I remove it I don't get this error. If I let the key stay not-null, during run time persistence fails. So I had to revert the mapping file at runtime for the persistence to go fine. It is only the tool that is misbehaving.
> ----------------> Error
> org.hibernate.tool.hbm2x.ExporterException: Error while processing t
> emplate pojo/javaclass.vm
> at org.apache.tools.ant.Task.perform(Task.java:373)
> at org.apache.tools.ant.Target.execute(Target.java:341)
> at org.apache.tools.ant.Target.performTasks(Target.java:369)
> at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
> at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
> at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
> at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
> at org.apache.tools.ant.Main.runBuild(Main.java:668)
> at org.apache.tools.ant.Main.startAnt(Main.java:187)
> at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
> at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
> Caused by: org.hibernate.tool.hbm2x.ExporterException: Error while processing template pojo/javaclass.vm
> at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:89)
> at org.hibernate.tool.hbm2x.POJOExporter.runVelocity(POJOExporter.java:78)
> at org.hibernate.tool.hbm2x.POJOExporter.exportPersistentClass(POJOExporter.java:61)
> at org.hibernate.tool.hbm2x.POJOExporter.start(POJOExporter.java:111)
> at org.hibernate.tool.ant.GeneratorTask.execute(GeneratorTask.java:33)
> at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
> at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
> at org.apache.tools.ant.Task.perform(Task.java:364)
> -----------------
> mapping files
> -----------> Base class
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
> "-//Hibernate/Hibernate Mapping DTD//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
> <hibernate-mapping package="test.resources.core">
> <class
> name="Resource"
> table="Resource" polymorphism="explicit"
> >
> <id
> name="Id"
> type="integer"
> column="resourceId"
> >
> <meta attribute="use-in-equals">true</meta>
> <generator class="hilo">
> <param name="table">ResourceIdTracker</param>
> <param name="column">resourceId</param>
> </generator>
> </id>
> <property
> name="ResourceName"
> column="resourceName"
> type="string"
> not-null="true"
> length="80"
> />
> <property
> name="ResourceDescription"
> column="resourceDescription"
> type="string"
> not-null="true"
> length="255"
> />
> <property
> name="ResourceTypeId"
> column="resourceTypeId"
> type="integer"
> not-null="true"
> length="10"
> />
> <property
> name="CreatedBy"
> column="createdBy"
> type="integer"
> not-null="true"
> length="10"
> />
> <property
> name="CreatedTime"
> column="createdTime"
> type="timestamp"
> not-null="true"
> length="23"
> />
> <property
> name="LastUpdatedBy"
> column="lastUpdatedBy"
> type="integer"
> not-null="true"
> length="10"
> />
> <property
> name="LastUpdatedTime"
> column="lastUpdatedTime"
> type="timestamp"
> not-null="true"
> length="23"
> />
> <property
> name="Deleted"
> column="deleted"
> type="string"
> not-null="true"
> length="1"
> />
> <set name="ResourcePermissions" table="ResourcePermission" inverse="true">
> <key column="resourceId" not-null="true"/>
> <one-to-many class="ResourcePermission"/>
> </set>
> </class>
> </hibernate-mapping>
> --------------------> JOINED SUBCLASS
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
> "-//Hibernate/Hibernate Mapping DTD//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
> <hibernate-mapping package="test.resources.chartbook">
> <joined-subclass
> name="ChartDefinition"
> table="ChartDefinition"
> extends="test.resources.core.Resource"
> >
> <key column="chartDefinitionId"/>
> <property
> name="FromDate"
> column="fromDate"
> type="integer"
> not-null="false"
> length="10"
> />
> <property
> name="ToDate"
> column="toDate"
> type="integer"
> not-null="false"
> length="10"
> />
> <property
> name="Period"
> column="period"
> type="string"
> not-null="false"
> length="32"
> />
> <property
> name="ViewType"
> column="viewType"
> type="string"
> not-null="false"
> length="32"
> />
> <!-- This works but requires bidrecitional setting -->
> <one-to-one name="chartAxisDefinition" cascade="all-delete-orphan" class="ChartAxisDefinition"/>
> <!-- having a not-null attribute on key is thowing error while generating classes where as -->
> <!-- not having it is throwing an error while inserting -->
> <!-- for now removing while code generation and adding it back while run time -->
> <!-- NEED TO ADDRESS THIS -->
> <list name="ChartSeries" cascade="all-delete-orphan" inverse="false" lazy="false">
> <key column="chartDefinitionId" not-null="true"/>
> <list-index column="position" />
> <one-to-many class="ChartSeries"/>
> </list>
> </joined-subclass>
> </hibernate-mapping>
> --------------> ONE TO MANY TARGET
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
> "-//Hibernate/Hibernate Mapping DTD//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
> <hibernate-mapping package="test.resources.chartbook">
> <class
> name="ChartSeries"
> table="ChartSeries"
> >
> <id
> name="Id"
> type="integer"
> column="chartSeriesId"
> >
> <generator class="hilo">
> <param name="table">ResourceIdTracker</param>
> <param name="column">resourceId</param>
> </generator>
> </id>
> <property
> name="Included"
> column="included"
> type="string"
> not-null="true"
> length="1"
> />
> <property
> name="SelectorTreeNodePath"
> column="selectorTreeNodePath"
> type="string"
> not-null="false"
> length="1024"
> />
> <property
> name="Attribute"
> column="attribute"
> type="string"
> not-null="false"
> length="50"
> />
> <property
> name="ColumnName"
> column="columnName"
> type="string"
> not-null="false"
> length="255"
> />
> <property
> name="Formula"
> column="formula"
> type="string"
> not-null="false"
> />
> <property
> name="AxisLocation"
> column="axisLocation"
> type="string"
> not-null="true"
> length="32"
> />
> <property
> name="Position"
> column="position"
> type="integer"
> not-null="true"
> length="10"
> insert="false"
> update="false"
> />
> </class>
> </hibernate-mapping>
> -------------- ONE TO ONE TARGET
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
> "-//Hibernate/Hibernate Mapping DTD//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
> <hibernate-mapping package="test.resources.chartbook">
> <class
> name="ChartAxisDefinition"
> table="ChartAxisDefinition"
> >
> <id
> name="Id"
> type="integer"
> column="chartAxisDefinitionId"
> >
> <generator class="foreign">
> <param name="property">ChartDefinition</param>
> </generator>
> </id>
> <property
> name="LeftAxisMin"
> column="leftAxisMin"
> type="java.lang.Double"
> not-null="true"
> length="15"
> />
> <property
> name="LeftAxisMax"
> column="leftAxisMax"
> type="java.lang.Double"
> not-null="true"
> length="15"
> />
> <property
> name="RightAxisMin"
> column="rightAxisMin"
> type="java.lang.Double"
> not-null="true"
> length="15"
> />
> <property
> name="RightAxisMax"
> column="rightAxisMax"
> type="java.lang.Double"
> not-null="true"
> length="15"
> />
> <property
> name="LeftAxisLabel"
> column="leftAxisLabel"
> type="string"
> not-null="true"
> length="32"
> />
> <property
> name="RightAxisLabel"
> column="rightAxisLabel"
> type="string"
> not-null="true"
> length="32"
> />
> <property
> name="ChartName"
> column="chartName"
> type="string"
> not-null="true"
> length="80"
> />
> <one-to-one name="ChartDefinition" class="ChartDefinition" constrained="true"/>
> </class>
> </hibernate-mapping>
--
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
16 years, 9 months