-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Caching vs. Versioning - either but not both?
PostPosted: Wed Jun 23, 2004 9:41 am 
Newbie

Joined: Mon Jun 21, 2004 2:21 pm
Posts: 7
Location: New York, NY
I am using Hibernate 2.1.3 and have some strange behavior. Im doing a proof of concept for standardizing on Hibernate here at work, so any help would be greatly appreciated.

It seems hibernate will not work if I use both a <version> and <cache> tag in the same persistent base class.

If I have caching enabled for the class, and the timestamp/version property mapped as a simple property, the mappings work fine.

Also if I have the timestamp property mapped as the <version> property, with no cache enabled, the mappings work fine.

But If I have both <version> and <cache> in the same mapping file, things get out of whack. First I get a PropertyAccess error telling me to turn off the reflection optimizer, which I did.

Then I ran under the debugger and watched what was going on. the AbstractEntityPersister setter[] gets out of sync with the value[], observed at this line of code, AbstractEntityPersister.221, so the setter for the version property which expects a timestamp, is being passed a String, which is the value of a different persistent property, and throwing an IllegalArgumentException....

Code:
for (int j=0; j<getHydrateSpan(); j++) getSetters()[j].set(object, values[j]);


Could it have something to do with the class hierarchy it looks something like this

Abstract Non Persistent Base Class A
Abstract Persistent Base Classes B,C,D extend A
Concrete Persistent Classes B1,B2,B3 extend B
Concrete Persistent Classes C1,C2,D3 extend C
Concrete Persistent Classes D1,C2,D3 extend D

The inheretence is mapped using table per subclass...

Thnaks for any help..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nowhere near enough information here.


Top
 Profile  
 
 Post subject: More info
PostPosted: Wed Jun 23, 2004 10:28 am 
Newbie

Joined: Mon Jun 21, 2004 2:21 pm
Posts: 7
Location: New York, NY
Sorry bout that... Here is a mapping file for the abstract persistent base class, B in the example above, the UserType in the version property maps a SQL date to a java Timestamp.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
package="market.territory.bean">

<class name="TerritoryBean" table="TERRITORY">
<!--<cache usage="read-write"/>-->
<id name="id" column="TERRITORY_TKEY">
<generator class="market.util.HibernateIdentifierGenerator">
<param name="sequence">TERRITORY_TKEY_SEQ</param>
</generator>
</id>
<version access="property" name="modifiedDate" type="market.util.TimestampDateType" column="MODIFIED_DATE"/>
<!-- no descriminator in table per subclass i.e joined subclass
<discriminator type="string" column="TERRITORY_TYPE"/>-->
<!--<property name="modifiedDate" not-null="true" column="MODIFIED_DATE"/>
--><property name="territoryType" column="TERRITORY_TYPE"/>
<property name="name" not-null="true" column="TERRITORY_NAME"/>
<property name="abbreviation" not-null="true" column="TERRITORY_ABBR"/>
<property name="description" column="TERRITORY_DESC"/>
<property name="modifiedBy" not-null="true" column="MODIFIED_BY"/>


<component name="lifetime">
<property name="creationTime" column="CREATION_DATE"/>
<property name="retirementTime" column="RETIREMENT_DATE"/>
</component>

<bag name="nameHistory" lazy="true" cascade="all">
<cache usage="read-write"/>
<key column="TERRITORY_TKEY"/>
<one-to-many class="NameHistoryBean"/>
</bag>


</class>

<query name="TerritoryBean.findByName">
from TerritoryBean as ter where ter.name = :name
</query>
<query name="TerritoryBean.findByAbbreviation">
from TerritoryBean as ter where ter.abbreviation = :abbr
</query>

</hibernate-mapping>



and here is the mapping for the concrete subclass of B

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
package="market.geographicterritory.bean">

<joined-subclass name="GeographicTerritoryBean" table="GEOGRAPHIC_TERRITORY" extends="market.territory.bean.TerritoryBean">

<key column="TERRITORY_TKEY"/>
<property name="placeType" not-null="true" column="GEOGRAPHIC_TERRITORY_TYPE"/>

<bag name="territoryChildren" table="GEOGRAPHIC_TERRITORY_DIVISION" lazy="true">
<key column="PARENT_GEO_TERRITORY_TKEY"/>
<many-to-many class="GeographicTerritoryBean" column="DIVISION_GEO_TERRITORY_TKEY"/>
</bag>


<!-- To Do: retrieves with separate sql where only 1 is needed -->
<one-to-one name="primeTerritory" class="PrimeTerritoryBean"/>


<bag name="nativeLanguages" table="NATIVE_LANGUAGE" lazy="true">
<cache usage="read-write"/>

<key column="TERRITORY_TKEY"/>
<many-to-many class="market.language.bean.LanguageBean" column="RIGHTS_LANGUAGE_TKEY"/>
</bag>


<bag name="territoryLeaves" table="GEOGRAPHIC_TERRITORY_LEAVES" lazy="true">
<cache usage="read-write"/>

<key column="PARENT_GEO_TERRITORY_TKEY"/>
<many-to-many class="GeographicTerritoryBean" column="TERRITORY_TKEY"/>
</bag>

</joined-subclass>


</hibernate-mapping>

The hibernate.cfg.xml with the OSCache config

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="show_sql">false</property>
<property name="hibernate.query.substitutions">true 'Y', false 'N'</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.datasource">ejbDataSource</property>
<property name="hibernate.jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.session_factory_name">hibernate</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.OSCacheProvider</property>

<mapping resource="market/territory/bean/TerritoryBean.hbm.xml"/>
<mapping resource="market/geographicterritory/bean/GeographicTerritoryBean.hbm.xml"/>

<mapping resource="market/geographicterritory/bean/PrimeTerritoryBean.hbm.xml"/>
<mapping resource="market/namedterritorygroup/bean/NamedTerritoryGroupBean.hbm.xml"/>
<mapping resource="market/territory/bean/NameHistoryBean.hbm.xml"/>
<mapping resource="market/territoryset/bean/TerritoryChoiceBean.hbm.xml"/>
<mapping resource="market/territoryset/bean/TerritorySetBean.hbm.xml"/>

<mapping resource="market/media/bean/MediaBean.hbm.xml"/>
<mapping resource="market/mediaset/bean/MediaChoiceBean.hbm.xml"/>
<mapping resource="market/mediaset/bean/MediaSetBean.hbm.xml"/>
<mapping resource="market/exhibmedia/bean/ExhibitionMediaBean.hbm.xml"/>
<mapping resource="market/distribmedia/bean/DistributionMediaBean.hbm.xml"/>
<mapping resource="market/language/bean/LanguageBean.hbm.xml"/>
<mapping resource="market/languageset/bean/LanguageChoiceBean.hbm.xml"/>
<mapping resource="market/languageset/bean/LanguageSetBean.hbm.xml"/>
<mapping resource="market/market/bean/MarketBean.hbm.xml"/>


</session-factory>
</hibernate-configuration>


The oscache.properties

cache.memory=true
cache.capacity=1000000
cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
cache.path=c:\\logs\\


Im running this in Weblogic 8.1 , going against Oracle 9.2

Thanks!


Top
 Profile  
 
 Post subject: log file entry
PostPosted: Wed Jun 23, 2004 1:23 pm 
Newbie

Joined: Mon Jun 21, 2004 2:21 pm
Posts: 7
Location: New York, NY
Here's the log file entry where the exception occurs

DimensionBean is the abstract non persistent base class

2004-06-22 11:21:05,737 ERROR property.BasicPropertyAccessor - IllegalArgumentException in class: market.dimension.DimensionBean, setter method of property: modifiedDate
2004-06-22 11:21:05,737 ERROR property.BasicPropertyAccessor - expected type: java.sql.Timestamp, actual value: java.lang.String


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.