[Hibernate] where clause for collections.

2004-10-27 Thread Caldas, Marcelo








I’ve been trying to use the where clause for
 on hibernate for quite a long time.

 

The main reason I’m using it is because we’re
implementing a soft-delete (setting a flag to 0, instead of a SQL DELETE
statement).

And then I use the where=”active_ind=1” to
retrieve only active children.

 

First problem is I’m getting “ambiguous column
name ‘active_ind’” because most of the tables have an
active_ind column – same name.

 

I tried solving this problem by adding the set name for the
where clause:  

 

It didn’t work, because the real name for the orgTypes
is “orgTypes0_”. Therefore orgTypes is not valid.

 

Shouldn’t it be better if I could specify a HQL for
the where clause and Hibernate put the sql together for me?

 

How can I solve this problem?

 

Thanks,

Marcelo.








Re: [Hibernate] where clause for collections.

2004-10-27 Thread Emmanuel Bernard






Caldas, Marcelo wrote:

  
  
  
  
   
  Shouldn’t it be better if
I could specify a HQL for
the where clause and Hibernate put the sql together for me?
  

No, usually where clause apply to non mapped columns.




FW: [Hibernate] where clause for collections.

2004-10-27 Thread Caldas, Marcelo








How can I solve my problem then?

 









From: Emmanuel Bernard [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 27, 2004
8:40 AM
To: Caldas, Marcelo
Cc:
[EMAIL PROTECTED]
Subject: Re: [Hibernate] where
clause for collections.



 



Caldas, Marcelo wrote: 

 

Shouldn’t it be better if I could specify a HQL
for the where clause and Hibernate put the sql together for me?

 

No, usually where clause apply to non mapped columns. 

 







Original message:

FROM: Caldas, Marcelo.

 

 

I’ve been trying to use the
where clause for  on hibernate for quite a long time.

 

The main reason I’m using it
is because we’re implementing a soft-delete (setting a flag to 0, instead
of a SQL DELETE statement).

And then I use the
where=”active_ind=1” to retrieve only active children.

 

First problem is I’m getting
“ambiguous column name ‘active_ind’” because most of
the tables have an active_ind column – same name.

 

I tried solving this problem by
adding the set name for the where clause:  

 

It didn’t work, because the
real name for the orgTypes is “orgTypes0_”. Therefore orgTypes is
not valid.

 

Shouldn’t it be better if I
could specify a HQL for the where clause and Hibernate put the sql together for
me?

 

How can I solve this problem?

 

Thanks,

Marcelo.

 








Re: [Hibernate] where clause for collections.

2004-10-27 Thread Gavin King
Caldas, Marcelo wrote:
And then I use the where=”active_ind=1” to retrieve only active children.
First problem is I’m getting “ambiguous column name ‘active_ind’” 
because most of the tables have an active_ind column – same name.

Hibernate should automatically prefix the column name. What does the 
generated SQL look like?

--
Gavin King
+61 410 534 454
+1 404 822 8349
callto://gavinking
Hibernate
[EMAIL PROTECTED]
http://hibernate.org
JBoss Inc
[EMAIL PROTECTED]
http://jboss.com

---
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] RE: [Opensymphony-oscache] RE: oscache and hibernate

2004-10-27 Thread March, Andres
I have received permission to contribute my hibernate oscache provider patch.  Here is 
the unified patch, the whole classes are attached:

Index: OSCache.java
===
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/OSCache.java,v
retrieving revision 1.6
diff -u -r1.6 OSCache.java
--- OSCache.java4 Jun 2004 05:43:45 -   1.6
+++ OSCache.java27 Oct 2004 16:26:30 -
@@ -1,8 +1,12 @@
 //$Id: OSCache.java,v 1.6 2004/06/04 05:43:45 steveebersole Exp $
 package net.sf.hibernate.cache;
 
+import java.util.Properties;
+
+import net.sf.hibernate.util.PropertiesHelper;
 import net.sf.hibernate.util.StringHelper;
 
+import com.opensymphony.oscache.base.Config;
 import com.opensymphony.oscache.base.NeedsRefreshException;
 import com.opensymphony.oscache.general.GeneralCacheAdministrator;
 
@@ -10,14 +14,28 @@
  * @author mailto:[EMAIL PROTECTED]">Mathias Bogaert
  */
 public class OSCache implements Cache {
+
+/** 
+ * The OSCache cache capacity property suffix. 
+ */
+public static final String OSCACHE_CAPACITY = "cache.capacity";
+
+private static final Properties OSCACHE_PROPERTIES = new Config().getProperties();
/** 
 * The OSCache 2.0 cache administrator. 
 */
-   private GeneralCacheAdministrator cache = new GeneralCacheAdministrator();
+   private static GeneralCacheAdministrator cache = new 
GeneralCacheAdministrator();
+
+private static Integer capacity = PropertiesHelper.getInteger(OSCACHE_CAPACITY, 
OSCACHE_PROPERTIES);
 
+static {
+if (capacity != null) cache.setCacheCapacity(capacity.intValue());
+}
+
private final int refreshPeriod;
private final String cron;
private final String regionName;
+private final String[] regionGroups;

private String toString(Object key) {
return String.valueOf(key) + StringHelper.DOT + regionName;
@@ -27,10 +45,7 @@
this.refreshPeriod = refreshPeriod;
this.cron = cron;
this.regionName = region;
-   }
-
-   public void setCacheCapacity(int cacheCapacity) {
-   cache.setCacheCapacity(cacheCapacity);
+this.regionGroups = new String[] {region};
}
 
public Object get(Object key) throws CacheException {
@@ -44,7 +59,7 @@
}
 
public void put(Object key, Object value) throws CacheException {
-   cache.putInCache( toString(key), value );
+   cache.putInCache( toString(key), value, regionGroups );
}
 
public void remove(Object key) throws CacheException {
@@ -52,11 +67,13 @@
}
 
public void clear() throws CacheException {
-   cache.flushAll();
+   cache.flushGroup(regionName);
}
 
public void destroy() throws CacheException {
-   cache.destroy();
+   synchronized (cache) {
+   cache.destroy();
+}
}
 
public void lock(Object key) throws CacheException {
Index: OSCacheProvider.java
===
RCS file: 
/cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/OSCacheProvider.java,v
retrieving revision 1.6
diff -u -r1.6 OSCacheProvider.java
--- OSCacheProvider.java4 Jun 2004 05:43:45 -   1.6
+++ OSCacheProvider.java27 Oct 2004 16:26:30 -
@@ -25,11 +25,7 @@
 * The OSCache CRON expression property suffix. 
 */
public static final String OSCACHE_CRON = "cron";
-   /** 
-* The OSCache cache capacity property suffix. 
-*/
-   public static final String OSCACHE_CAPACITY = "capacity";
-
+   
private static final Properties OSCACHE_PROPERTIES = new 
Config().getProperties();
 
/**
@@ -51,13 +47,8 @@
);
String cron = OSCACHE_PROPERTIES.getProperty( 
StringHelper.qualify(region, OSCACHE_CRON) );
 
-   // construct the cache
-   final OSCache cache = new OSCache(refreshPeriod, cron, region);
-   
-   Integer capacity = PropertiesHelper.getInteger( 
StringHelper.qualify(region, OSCACHE_CAPACITY), OSCACHE_PROPERTIES);
-   if ( capacity!=null ) cache.setCacheCapacity( capacity.intValue() );
-   
-   return cache;
+   // construct the cache
+return new OSCache(refreshPeriod, cron, region);
}
 
public long nextTimestamp() {





> -Original Message-
> From: Stefán Baxter [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 26, 2004 4:40 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [Opensymphony-oscache] RE: oscache and hibernate
> 
> Hi,
> 
> I have been using oscache for the past three years but we have recently
> added hibernate to our project. It's working fine with oscache but the
> mult

RE: [Hibernate] where clause for collections.

2004-10-27 Thread Caldas, Marcelo
Here's a snapshot of what's going on:

Hibernate: select orgtypes0_.organization_id as organiza5___,
orgtypes0_.organization_type_id as organiza1___,
orgtypes0_.organization_type_id as organiza1_2_, orgtypes0_._version as
_version2_, orgtypes0_.primary_ind as primary_3_2_,
orgtypes0_.organization_type as organiza4_2_, orgtypes0_.organization_id
as organiza5_2_, orgtypes0_._created_timestamp as _created6_2_,
orgtypes0_._created_by as _created7_2_, orgtypes0_._modified_timestamp
as _modifie8_2_, orgtypes0_._modified_by as _modifie9_2_,
orgtypes0_._active_ind as _active10_2_, vocabulary1_.vocabulary_id as
vocabula1_0_, vocabulary1_._version as _version0_,
vocabulary1_.vocabulary_type_id as vocabula3_0_,
vocabulary1_.abbreviation as abbrevia4_0_, vocabulary1_.private_ind as
private_5_0_, vocabulary1_.name as name0_, vocabulary1_.description as
descript7_0_, vocabulary1_._created_timestamp as _created8_0_,
vocabulary1_._created_by as _created9_0_,
vocabulary1_._modified_timestamp as _modifi10_0_,
vocabulary1_._modified_by as _modifi11_0_, vocabulary1_._active_ind as
_active12_0_, vocabulary2_.vocabulary_type_id as vocabula1_1_,
vocabulary2_._version as _version1_, vocabulary2_.controlled_ind as
controll3_1_, vocabulary2_.app_code as app_code1_, vocabulary2_.name as
name1_, vocabulary2_.description as descript6_1_,
vocabulary2_._created_timestamp as _created7_1_,
vocabulary2_._created_by as _created8_1_,
vocabulary2_._modified_timestamp as _modifie9_1_,
vocabulary2_._modified_by as _modifi10_1_, vocabulary2_._active_ind as
_active11_1_ from ORGANIZATION_TYPE orgtypes0_ left outer join
VOCABULARY vocabulary1_ on
orgtypes0_.organization_type=vocabulary1_.vocabulary_id left outer join
VOCABULARY_TYPE vocabulary2_ on
vocabulary1_.vocabulary_type_id=vocabulary2_.vocabulary_type_id where
orgtypes0_.organization_id=? and _active_ind=1

Oct 27, 2004 2:04:14 PM net.sf.hibernate.util.JDBCExceptionReporter
logExceptions
WARNING: SQL Error: 209, SQLState: S1000
Oct 27, 2004 2:04:14 PM net.sf.hibernate.util.JDBCExceptionReporter
logExceptions
SEVERE: Ambiguous column name '_active_ind'.
Oct 27, 2004 2:04:14 PM net.sf.hibernate.util.JDBCExceptionReporter
logExceptions
WARNING: SQL Error: 209, SQLState: S1000
Oct 27, 2004 2:04:14 PM net.sf.hibernate.util.JDBCExceptionReporter
logExceptions
SEVERE: Ambiguous column name '_active_ind'.
Oct 27, 2004 2:04:14 PM net.sf.hibernate.JDBCException 
SEVERE: could not initialize collection:
[gov.phindir.platform.organization.tran
sferObjects.PhindirOrganization.orgTypes#23]
java.sql.SQLException: Ambiguous column name '_active_ind'.

As you can see, the first line reads select "orgtypes0_"
And last line where "_active_ind-1", but I have an _active_ind on every
single table part of that from clause.



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gavin
King
Sent: Wednesday, October 27, 2004 9:49 AM
To: Caldas, Marcelo
Cc: [EMAIL PROTECTED]
Subject: Re: [Hibernate] where clause for collections.

Caldas, Marcelo wrote:

>
> And then I use the where="active_ind=1" to retrieve only active
children.
>
> First problem is I'm getting "ambiguous column name 'active_ind'" 
> because most of the tables have an active_ind column - same name.
>
Hibernate should automatically prefix the column name. What does the 
generated SQL look like?

-- 
Gavin King
+61 410 534 454
+1 404 822 8349
callto://gavinking

Hibernate
[EMAIL PROTECTED]
http://hibernate.org

JBoss Inc
[EMAIL PROTECTED]
http://jboss.com



---
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



---
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&op=click
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel