Shortcomings in org.hibernate.id.enhanced.TableGenerator class
by Tom Muldoon
I'm working with the org.hibernate.id.enhanced.TableGenerator class and I've noticed a couple of shortcomings (imho). First and foremost, it creates one row in the hibernate_sequences table for each configured segment_value (as opposed to one row for each "target_table" as implemented within the MultipleHiLoPerTableGenerator). Given the fact that my id column is defined in an abstract BaseEntity class, I can't use the enhanced TableGenerator class as is (since one sequence for all of my entities is not viable for my application). Which leads me to my second point. All of the member variables are declared as private, instead of protected, which makes extending the class for the purpose of overriding the configure method impossible.
For what it's worth, here's the change that I had planned to make (in the configure method) ...
Change the setting of the segmentValue from ...
segmentValue = params.getProperty( SEGMENT_VALUE_PARAM );
... to
segmentValue = params.getProperty(TABLE);
Of course, such a change would change the class behavior significantly - using targetTable instead of segmentValue as the variable name would probably make sense.
So, with that said, is another class worth-while (assuming that such a change to the existing class would break backwards compatability)?
And, on a related note, the enhanced TableGenerator is cluster safe, right?
Thoughts?
PS. I entered a jira improvement yesterday - here's the link ...
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3249
15 years, 10 months
remove object from collection without collection fetching
by Renat
Hello,
I have bi-directional association between parent/child.
Parent can have too many children and I want to add and
remove to "children" (inverse=true) collection without
loading collection.
"children" collection mapped as <bag>. With adding to
collection I have no problem, but when I try to remove
from this collection, collection perform initialization.
Java class:
public class MyObject
{
private Long id;
private MyObject parent;
private Collection< MyObject > children = new
ArrayList< MyObject >();
public MyObject()
{
}
public void addChild( MyObject object )
{
object.parent = this;
children.add( object );
}
public void removeChild( KAObject object )
{
object.parent = null;
children.remove( object ); // initialization of
collection. it is strange, because too many children.
}
}
Database:
table: my_object
fields:
- id
- parent_id
Mapping:
<hibernate-mapping>
<class name="MyObject" table="my_object" >
<id name="id" column="id" type="long">
<generator class="sequence">
<param name="sequence">my_object_seq</param>
</generator>
</id>
<many-to-one name="parent" class="MyObject"
column="parent_id" lazy="no-proxy" cascade="evict"
access="field" />
<bag name="children" inverse="true" lazy="true"
cascade="all-delete-orphan" access="field">
<key column="parent_id" />
<one-to-many class="MyObject" />
</bag>
</class>
I want for example move child to another parent.
MyObject newParent = session.get(MyObject.class, 1);
MyObject child = session.get(MyObject.class, 2);
MyObject oldParent = myObject.getParent();
oldParent.removeChild(child); // initialization of
collection. it is strange, because too many children.
newParent.addChild(child) // no initialization
Why PersistentBag.remove is not implemented like
PersistentBag.add ?
public boolean add(Object object) {
if ( !isOperationQueueEnabled() ) {
write();
return bag.add(object);
}
else {
queueOperation( new SimpleAdd(object) );
return true;
}
}
public boolean remove(Object o) {
initialize( true );
if ( bag.remove( o ) ) {
dirty();
return true;
}
else {
return false;
}
}
I think problem, that interface of
Collection.remove(Object) should return result of remove.
But what aboutm if I never use this result.
I can write own implementation of PersistentBag with
overrided method remove. and use it in User Collection
Type.
public boolean remove( Object o )
{
if ( !isOperationQueueEnabled() )
{
write();
return bag.remove( o );
}
else
{
queueOperation( new SimpleRemove( o ) );
return true; // this result can be wrong
}
}
final class SimpleRemove implements DelayedOperation {
private Object value;
public SimpleRemove(Object value) {
this.value = value;
}
public void operate() {
bag.remove(value);
}
public Object getAddedInstance() {
return null;
}
public Object getOrphan() {
return value;
}
}
In this implementation I should always remember, that
result of Collection.remove(Object) can be wrong and never
use it.
May be anybody know another solution?
15 years, 10 months
Search and Shard topic "up"
by Sanne Grinovero
Hi all,
I've verified a scaring design problem I found in the forum, it
appears that Search and Shards can't be used together:
http://forum.hibernate.org/viewtopic.php?t=986285
The problem is that Search needs to cast the session to an
EventSource, but when using Shards the provided
session is "org.hibernate.shards.session.ShardedSessionImpl", which
does not implement org.hibernate.event.EventSource;
also it doesn't look like trivial to add the missing methods.
Any thought about it? Should I open a JIRA: in which category, Search or Shards?
IMHO I think the Search shouldn't do this casting, so it would be a
Search design problem,
but it's difficult to keep the code decoupled.
Sanne
15 years, 10 months
Custom SQL update problem
by Anatoli Atanasov
Dear Experts,
I have an issue with the Hibernate custom sql commands. I have the mapping
file:
*<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.gsk.europepharma.clinfit.model.entities.InputFile"
table="INPUT_FILE" schema="CLINFIT">
<id name="id">
<column name="ID" sql-type="number" length="10" precision="0"
not-null="true"/>
<generator class="sequence">
<param name="sequence">S_INPUT_FILE</param>
</generator>
</id>
<property name="fileType">
<column name="FILE_TYPE" sql-type="varchar2" length="20"
precision="0" not-null="true"/>
</property>
<property name="forDate">
<column name="FOR_DATE" sql-type="date" length="7" precision="0"
not-null="true"/>
</property>
<property name="statusCode">
<column name="STATUS_CODE" sql-type="varchar2" length="20"
precision="0" not-null="true"/>
</property>
<property name="datetimeLastProcessed">
<column name="DATETIME_LAST_PROCESSED" sql-type="date"
length="7" precision="0" not-null="false"/>
</property>
<property name="datetimeStatusLastChanged">
<column name="DATETIME_STATUS_LAST_CHANGED" sql-type="date"
length="7" precision="0" not-null="true"/>
</property>
<property name="invalidDataMessage">
<column name="INVALID_DATA_MESSAGE" sql-type="varchar2"
length="1000" precision="0" not-null="false"/>
</property>
<many-to-one name="country"
class="com.gsk.europepharma.clinfit.model.entities.CCountry">
<column name="COUNTRY_ID" not-null="true"/>
</many-to-one>
<!-- TODO: comment it -->
<sql-update callable="true">{ ? = call
BUSINESS_LOGIC_PKG.CHANGE_INPUT_FILE_STATUS (?, ?, ?, ?, ?, ?, ?,
?)}</sql-update>
</class>
</hibernate-mapping>*
When my objects at runtime are updated I am getting the following
Exception:
*Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 9
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at
oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1729)
at
oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:10547)
at
oracle.jdbc.driver.OracleCallableStatement.addBatch(OracleCallableStatement.java:2009)
at
org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:31)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2408)
... 25 more
*The update function - *BUSINESS_LOGIC_PKG.CHANGE_INPUT_FILE_STATUS *is
implemented in Oracle 10g R2. Before this I checked the order of parameters
with debuging the static queries. I went through the code and I could not
find any where registerOutputParameter invocation to the callable statement,
so the result can be consumed back to Hibernate.
Can anybody help me!
Thanks in advance!
Best regards,
Anatoli
--
Anatoli Atanasov
mobile: (+359) 888 32 06 49
--
Anatoli Atanasov
mobile: (+359) 888 32 06 49
15 years, 10 months
TransactionException
by Xinsheng Chen
Hi,
I am using
hibernate-3.2.6.ga
mysql-connector-java-5.1.5
spring-framework-2.5.1
liferay-portal-tomcat-6.0-4.3.6
My portlet application runs fine for most of the time.
However, in the morning when I run the Web application
and save user input into the database at the first
try, it throws exception. I got the following from
Tomcat Catalina.out.
2008-05-06 14:41:17,461 WARN
[org.springframework.web.portlet.DispatcherPortlet] -
Handler execution resulted in exception - forwarding
to resolved error view
org.springframework.transaction.CannotCreateTransactionException:
Could not open Hibernate Session for transaction;
nested exception is
org.hibernate.TransactionException: JDBC begin failed:
at
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:521)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.TransactionException: JDBC
begin failed:
at
org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68)
at
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:490)
... 110 more
Caused by:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
I have browsed some Web sites. It is said that the
problem is stale database connection. Following the
advice I have added the following lines in my
hibernate configuration file:
<prop
key="hibernate.c3p0.acquire_increment">3</prop>
<prop
key="hibernate.c3p0.idle_test_period">30</prop>
<prop
key="hibernate.c3p0.timeout">60</prop>
<prop
key="hibernate.c3p0.max_size">15</prop>
<prop
key="hibernate.c3p0.max_statements">0</prop>
<prop
key="hibernate.c3p0.min_size">3</prop>
But it does not help.
Any help would be appreciated!
Regards,
Robert Chen
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
15 years, 10 months
Migration to Hibernate Core 3.3
by Emmanuel Bernard
I have been working in the past two days to make the build system, and
the projects compatible with the migration to Core 3.3:
- Hibernate Commons Annotations
- Hibernate Annotations
- Hibernate Validator
- Hibernate Search
- Hibernate EntityManager
Sorry I forgot Hibernate Shards, but I will look at it after JavaOne
I did:
- remove the dependency to the hibernate core build structure (both
the documentation and the build system)
- moved almost all dependencies to ivy
- added a pom for each project
- added a 'ant deploy' task that deploys artifacts to a local maven
repo
Still on the todo list before a release:
- migrate to slf4j instead of commons-logging for all projects
- make use of the new enhanced id generators if it makes sense
It means the developments of trunk are all based on Core 3.3 (trunk)
I would appreciate feedback on the build, the POMs and the rest. Let
me know if there are any issues.
15 years, 11 months
Hibernate Search 3.1
by Emmanuel Bernard
Hibernate Search 3.1 will arrive sooner than expected to align with
Hibernate Core 3.3
If you have some compatibility breaks in mind, speak up. Also we need
to focus on closing the features implying Core 3.3 first (I have the
close hooks of the SF in mind but there might be others). The
additional features will go in a 3.2. I don't know if we should go for
a beta or straight to a CR for HSearch 3.1, WDYT.
There are code changes but there are not too big.
Emmanuel
PS I had hoped to keep HSearch 3.1 compatible with Core 3.2 but
because we extends Session (which has a new doWork(Work) method), we a
pretty much screwed.
15 years, 11 months
Hibernate Core 3.3.0.CR1
by Steve Ebersole
The Hibernate team is pleased to announce the release of Hibernate
Core 3.3.0.CR1. This release features:
* a redesign of the "second level cache" SPI
* a new integration with JBossCache 2.x taking full advantage of this
new SPI (special thanks to Brian Stansberry for his help and hard work
on this)
* introduction of the org.hibernate.jdbc.Work API for performing JDBC
work without interfering with connection release modes
Another change in this release from previous releases is the switch
Maven, which has a few implications for users. The biggest is the
splitting of the project into what Maven terms modules. Essentially
we utilized modules for isolating optional features sets. For
example, there is a module for the integration of JBoss Cache 2.x as
the "second level cache". In terms of users, that means that there is
a separate jar defining that integration. But also, for those using
Maven or another library which understands its notion of transitive
dependencies, the specific dependencies of JBoss Cache 2.x are
isolated to just that module.
The Maven artifacts are deployed to the JBoss Maven repository (http://repository.jboss.org/maven2
) under the groupId of org.hibernate. The main artifactId is
hibernate-core. Over the next few days we will be writing up some
descriptions for the web site describing the various modules/
artifactIds and the purpose of each.
For those not using Maven, we do still build a dist for upload to
SourceForge: http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=12...
There have been a few issues identified with the SourceForge bundles.
They have all been pretty minor and none code related. The issue with
the biggest impact is probably the fact that a few dependencies are
missing from the bundles. We have identified jta.jar, javaassist and
cglib (and its asm deps). These will be corrected for another CR and
eventual GA.
-----------------------------
Steve Ebersole
Project Lead
http://hibernate.org
steve(a)hibernate.org
15 years, 11 months
hibernate-documentation CI job
by Aleksandar Kostadinov
Hallo,
This mail is to announce the newly created hibernate-documentation job.
It is now setup to run daily. Let me know if you want artifacts deployed
on some repository as now it doesn't deploy anywhere.
Thanks,
Aleksandar
15 years, 11 months