Dialect support for SQL comments.
by Daniel Bell
Hi,
I have recently tried turning on SQL comments in hibernate 3.2.6.ga.
However, I found that our database (informix 7.31) did not support SQL
where the comment was at the start of the comment. Instead, the comment
needed to be after the SQL. For example:
/* not accepted by informix 7.31*/ select * from systables;
select * from systables /* accepted by informix 7.31*/
Because of this, I have added a method to the Dialect for adding comments:
/**
* Add a comment to the SQL string.
*
* @param sql StringBuffer holding the SQL.
* @param comment Comment to add to the SQL. May be null.
*/
public void addCommentToSql(StringBuffer sql, String comment) {
if (StringHelper.isNotEmpty(comment))
sql.insert(0, "/* " + comment + " */ ");
}
Thus, the default implementation provides the same functionality as
before. However, derived Dialects may override this method to add the
comment in a different location.
It is also possible to add additional comments in the derived Dialect.
In our case, we also add the Java thread ID.
I have included a complete patch for this change for hibernate 3.2.6.GA.
Please consider its inclusion in Hibernate.
Thanks,
Daniel.
15 years, 6 months
HSearch: Using sharding and avoiding query on multiple shards
by Emmanuel Bernard
Today, in Hibernate Search, a query is applied on all shards. We use a
MultiReader to wrap them together.
In some sharding scenario, it makes sense to apply the query on a
single shard or a subset of the shards.
We could add the following API to IndexShardingStrategy
public DirectoryProvider<?>[]
getDirectoryProvidersForQuery(o.a.l.search.Query query);
The query could be analyzed by the sharding strategy to detect boolean
queries on their sharding criteria
//query building
BooleanQuery bQuery = new BooleanQuery();
bQuery.add(regularQuery, Occur.MUST);
bQuery.add( new TermQuery( new Term("distributor.id", "2"),
Occur.MUST ); //only occurs in shard 1
public DirectoryProvider<?>[]
getDirectoryProvidersForQuery(o.a.l.search.Query query) {
if (query instanceof BooleanQuery) {
List<BooleanClause> clauses =
BooleanQuery.class.cast(query).clauses
}
int restrictedShard;
boolean isAllMust = true;
for (BooleanClause clause : clauses) {
if (clause.getOccur() != Occur.MUST) { isAllMust = false; break; }
if ( clause.getQuery() instanceof TermQuery ) {
Term term = TermQuery.class.cast( clause.getQuery() ).getTerm();
if (term.field().equals("distributor.id")) { restrictedShard =
Integer.parse(term.text(); }
}
}
if (isAllMust && restrictedShard != null) return new Provider[]
{ providers[restrictedShard-1] };
else return providers;
}
That's very flexibile but quite hard to implement correctly especially
since the query tree structure might not be trivial
The alternative strategy is to have the following API on
IndexShardingStrategy
public DirectoryProvider<?>[] getDirectoryProvidersForQuery(Object
hint);
and a corresponding fullTextQuery.setShardHint(Object);
A query could "know it targets shard 2 and pass the information to the
strategy through a standard language:
fullTextQuery.setShardHint("Sony");
public DirectoryProvider<?>[] getDirectoryProvidersForQuery(Object
hint) {
if (String.class.isInstance(hint) &&
String.class.cast(hint).equals("Sony")) {
return new Provider[] { providers[2] }
}
else {
return providers;
}
}
WDYT? How useful would that be?
--
Emmanuel Bernard
http://in.relation.to/Bloggers/Emmanuel | http://blog.emmanuelbernard.com
| http://twitter.com/emmanuelbernard
Hibernate Search in Action (http://is.gd/Dl1)
16 years, 3 months
Copyright on hibernate XML interface?
by Oliver Plohmann
Hello,
I already posted this question to a hibernate forum but didn't receive
any answer. That's why I saw no way round posting to this mailing list.
I'm working on a mapping tool that maps Java objects to RFCs. This is
somewhat similar to mapping Java objects to relational database tables
(though much simpler). I therefore got the idea to use the hibernate
hbm.xml mapping syntax for this Java-to-RFC mapping tool, because there
is no point in re-inventing the wheel and many many people know
hibernate and will therefore quickly feel at home when using this
Java-to-RFC mapping tool if it uses the same mapping XML syntax as
hibernate.
My question is now whether also this hbm.xml mapping syntax is
completely free and may be used for another purpose than hibernate
itself or whether permission has to be granted by the authors of
hibernate. I just want to be really sure before I start, because
changing the mapping syntax in the middle of the race is a lot of work.
Thanks in advance, Oliver Plohmann
16 years, 3 months
Re: [jbosscache-dev] REPEATABLE_READ in JBC as Hibernate 2nd Level Cache
by Brian Stansberry
Galder Zamarreno wrote:
> Paul Ferraro wrote:
>> refresh() always goes to the db, and only potentially triggers a 2LC
>> update - not a read.
>>
[OT] A concern I have is whether the refresh() removes the item from the
2LC before doing the subsequent Hibernate cache put(). If not our
putForExternalRead() usage will prevent the new value being placed in
the cache.
>> Perhaps we should revisit whether the scenario below warrants the cost
>> of repeatable_read, given that entity eviction from session cache is
>> typically used only to minimize memory usage when iterating through
>> large results, i.e. when an entity is not likely to be re-read within
>> the current transaction.
Yes. R_C will be the default config; this stuff is really something to
document, and to add an alternate R_R config as a convenience for those
who actually need it. See
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3390
This whole discussion has me thinking about the use of the OPTIMISTIC
configs as the default. The main benefit of OPTIMISTIC is allowing an
R_R-like semantic without blocking writes. But it comes as a cost.
(Again, we're talking defaults here, not whether O/L is 'supported'.)
>
> Hmmmm, this sounds like a bad practice to me or at least not very
> performant. Evict/clear something within a transaction and then re-get it.
>
Doing an evict() makes perfect sense in some scenarios (to control
memory). Doing a subsequent re-read can easily happen if the logic is
complex. (Agreed, if it happens a lot that's a sign of a design flaw in
the app.) But to then expect R_R from the second read: that for sure
makes it an edge case.
> Brian, did you use 2nd level cache in your previous use case?
>
No.
>>
>> On Thu, 2008-07-17 at 16:59 -0500, Brian Stansberry wrote:
>>> Hmm, good point. Potentially also Session.refresh(...), although I'm
>>> not sure if the implementation of that method skips the 2LC and goes
>>> right to the db.
>>>
>>> Paul Ferraro wrote:
>>>
>>>> After thinking this through, the only scenario I can think of where the
>>>> 2LC would be subject to a repeated read is after a session cache
>>>> eviction (i.e. via Session.clear() or Session.evict(...)). Without
>>>> REPEATABLE_READ isolation on the 2LC, any subsequent request withing
>>>> the
>>>> same transaction for an evicted entity could return an updated
>>>> value, if
>>>> the cache was updated by a concurrent request.
>>>>
>>>> Paul
>>>>
>>>> On Thu, 2008-07-17 at 12:59 -0500, Brian Stansberry wrote:
>>>>> Can anyone see a reason to use REPEATABLE_READ as the JBoss Cache
>>>>> isolation level in the 2nd level cache use case? I'm not seeing
>>>>> one, and it certainly hurts performance by forcing cache writes to
>>>>> block waiting for an earlier tx that did a read to commit.
>>>>>
>>>>> There are 4 types of data cached:
>>>>>
>>>>> 1) Entities
>>>>>
>>>>> If an entity is read from the 2LC, for the life of the tx it will
>>>>> be cached in the Session, so AIUI there should be no second read
>>>>> during the tx. So no benefit to RR.
>>>>>
>>>>> 2) Collections
>>>>>
>>>>> Same as entities.
>>>>>
>>>>> 3) Queries
>>>>>
>>>>> If an application executes a query twice in the same tx, I wouldn't
>>>>> think they'd expect the same result. In any case, if an update to
>>>>> the query cache is blocking waiting for a tx that previously read
>>>>> the query result to release, the existence of the update that
>>>>> means the underlying entities and their timestamps have changed. So
>>>>> a repeated read of the cached query will just result in it being
>>>>> discarded as out of date anyway.
>>>>>
>>>>> 4) Timestamps
>>>>>
>>>>> Here you don't want an RR semantic. You always want to get the most
>>>>> up-to-date data.
>>>>>
>>>>>
>>>>> Anyone see any holes in my thinking?
>>>>>
>>>>> --
>>>>> Brian Stansberry
>>>>> Lead, JBoss AS Clustering
>>>>> JBoss, a division of Red Hat
>>>>> _______________________________________________
>>>>> jbosscache-dev mailing list
>>>>> jbosscache-dev(a)lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/jbosscache-dev
>>>
>>
>> _______________________________________________
>> jbosscache-dev mailing list
>> jbosscache-dev(a)lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jbosscache-dev
>
--
Brian Stansberry
Lead, AS Clustering
JBoss, a division of Red Hat
brian.stansberry(a)redhat.com
16 years, 4 months
(Newbie question) Where to find the Hibernate3 module in svn?
by Hugh M
I am trying to check out the source for hibernate according to instructions
on http://www.hibernate.org/6.html.
This page refers to the module "Hibernate3" in a couple of places, and in
one spot even provides an svn command
that suggests where I can get the branched version:
Important note, the current Hibernate ext trunk works with Hibernate Core
> 3.2, be sure to get Hibernate3 from svn co http://anonsvn.jboss.org/repos/
> hibernate/branches/Branch_3_2/Hibernate3
>
But when I try to grab that module I do not find it! And I spent some time
poking around the repository and didn't see
any modules by the name of Hibernate3!
Any suggestions and/or insight about where I can find this would be very
appreciated. Thanks in advance,
Hugh
16 years, 4 months