[Hibernate-JIRA] Created: (HHH-2464) allow SequenceGenerator and TableGenerator to define increment and initial
by Steve Ebersole (JIRA)
allow SequenceGenerator and TableGenerator to define increment and initial
---------------------------------------------------------------------------
Key: HHH-2464
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2464
Project: Hibernate3
Type: Improvement
Components: core
Reporter: Steve Ebersole
Assigned to: Steve Ebersole
Fix For: 3.2.3
Add two new parameters to SequenceGenerator and TableGenerator as follows:
1) 'initial' - the initial value from which to start generating values. This one really only has an effect during schema export when creating the underlying structures. For sequences this would require the sequence to be able to define the "start with" value ala Oracle. For tables, this would be the value we initially insert into the table on creation.
2) 'increment' - The number by which values in the underlying DB structure are incremented. The basic idea is to minimize the number of times we need to hit the database in order to generate id values. Historically, both SequenceGenerator and TableGenerator hit the database each and every time an id value is requested. However, via this increment, we could essentially create a pool of available id values in memory and use that pool of values as id values. Only when the pool is exhausted would we need to hit the database. There are 2 aspects to how this new 'increment' param would affect the implementations:
a) how values would be retrieved from the underlying structure. For sequences, this would require that the sequences be able to define the increment ('increment by' in Oracle-speak); it would then take care of the rest of the deatils to this aspect. For tables, we would need to change the way we perform the updates after value retrieval to use the increment rather than the 1.
b) return values from this "pool" on calls to #generate(...) as long as values still exist in the pool; if not rebuild the pool values...
--
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
17 years, 9 months
[Hibernate-JIRA] Created: (HSEARCH-26) @Field( groups=... )
by Sylvain Vieujot (JIRA)
@Field( groups=... )
--------------------
Key: HSEARCH-26
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-26
Project: Hibernate Search
Type: New Feature
Components: query
Versions: FIRST
Reporter: Sylvain Vieujot
To search on multiple fields, one ugly solution is to concatenate all the entity's searchable fields in a big text that is indexed.
A cleaner solution is to use an org.apache.lucene.queryParser.MultiFieldQueryParser
This parser requires a String[] of the fields to search on.
To avoid having to give this (long) list of files to every query, and to have to manage it by hand, the idea is to have field "groups".
So you could add a parameter to the @Field annotation as in this example :
@Entity
@Indexed
public CV {
@Field( Indexed.TOKENIZED, queryGroups={"all"} )
String name;
@Field( Indexed.TOKENIZED, queryGroups={"accounting"} )
String bankAccount;
@Field( Indexed.TOKENIZED, queryGroups={"accounting","backOffice"} )
String address;
@SearchableEmbeddeable( queryGroups={"accounting","backOffice"} )
MedicalInfo mi;
}
Those groups could be used like security roles in servlets.
In the above examples, you could ask for the list of searchable fields for the accountants :
String[] searchableFieldsForAccountants = ContextHelper( session ).getDocumentBuilder( CV.class ).getFieldsForGroup( "accountants" );
Then you could construct the query parser :
luceneQuery = new MultiFieldQueryParser( searchableFieldsForAccountants getAnalyzer() );
--
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
17 years, 9 months
[Hibernate-JIRA] Updated: (HHH-1866) NullPointerException in org.hibernate.util.ComparableComparator
by Brian Stansberry (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1866?page=all ]
Brian Stansberry updated HHH-1866:
----------------------------------
Attachment: OptimisticTreeCache.patch
Attached is a patch to the 3.2 branch version of OptimisticTreeCache that avoids the NPE. A JBoss EJB3 user using org.jboss.ejb3.entity.OptimisticJBCCache with this change in it reports that their issues with null DataVersions went away. (OptimisticJBCCache is based on OptimisticTreeCache and is identical in this section of the code.)
> NullPointerException in org.hibernate.util.ComparableComparator
> ---------------------------------------------------------------
>
> Key: HHH-1866
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1866
> Project: Hibernate3
> Type: Bug
> Versions: 3.2.0.cr2
> Environment: - Hibernate 3.2.0 CR2
> - Spring 1.2.5
> - JBoss Cache 1.4
> - Oracle 9i
> - Windows and Linux
> Reporter: Eduard Hildebrandt
> Attachments: OptimisticTreeCache.patch
>
>
> I think that org.hibernate.util.ComparableComparator or OptimisticTreeCache.DataVersionAdapter has a bug.
> "return ((Comparable) x).compareTo(y);" throws a NullPointerException if x is a null pointer.
> org.hibernate.util.ComparableComparator. compare(..) is called from OptimisticTreeCache.DataVersionAdapter in line "return versionComparator.compare( previousVersion, other ) > 1;".
> We get this NullPointerExption if we use Hibernate with org.hibernate.cache.OptimisticTreeCacheProvider which causes an org.springframework.transaction.UnexpectedRollbackException.
> Greetings from Germany!
--
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
17 years, 9 months
[Hibernate-JIRA] Commented: (HHH-817) using projections is causing SQL query error on oracle (ORA-00904 error)
by Chris Federowicz (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
Chris Federowicz commented on HHH-817:
--------------------------------------
I apologize for the lack of formatting in the above class
> using projections is causing SQL query error on oracle (ORA-00904 error)
> ------------------------------------------------------------------------
>
> Key: HHH-817
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
> Project: Hibernate3
> Type: Bug
> Versions: 3.0.5
> Environment: Oracle 9.2.0.6, Hibernate 3.0.5, Spring Framework 1.2.2 based application working on Jakarta Tomcat 5.0.28
> Reporter: Michal Jastak
> Priority: Minor
>
>
> following java code:
> protected Entity loadEntityLightweight(Serializable entityId) throws DataAccessException {
> Criteria criteria = getSession().createCriteria(Entity.class);
> ProjectionList projectionList = Projections.projectionList();
> projectionList.add(Property.forName(BaseEntity.PROP_ID), BaseEntity.PROP_ID);
> projectionList.add(Property.forName(BaseEntity.PROP_TYPE), BaseEntity.PROP_TYPE);
> criteria.setProjection(projectionList);
> criteria.add(Restrictions.eq(BaseEntity.PROP_ID, entityId));
> criteria.setResultTransformer(new AliasToBeanResultTransformer(Entity.class));
> return (Entity) criteria.uniqueResult();
> }
> generates following SQL query:
> select this_.id as y0_, this_.type as y1_ from entities this_ left outer join facilities this_1_ on this_.id=this_1_.id left outer join users this_2_ on this_.id=this_2_.id left outer join addresses address2_ on this_.address_id=address2_.id left outer join entities entity3_ on this_2_.employer_id=entity3_.id left outer join facilities entity3_1_ on entity3_.id=entity3_1_.id left outer join users entity3_2_ on entity3_.id=entity3_2_.id where y0_=?
> y0_ = ? expression in where clause is causing a 904 error on Oracle 9:
> ORA-00904: "Y0_": invalid identifier
> hibernate dialect: org.hibernate.dialect.Oracle9Dialect
> mapping for Entity class:
> <?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 default-lazy="false" default-cascade="save-update">
>
> <class name="Entity" table="entities" mutable="true">
> <id name="id" type="java.lang.Long" unsaved-value="null">
> <generator class="sequence">
> <param name="sequence">entities_id_seq</param>
> </generator>
> </id>
> <many-to-one name="address" class="Address" column="address_id" />
> ...
> <!--
> - Facilities
> -->
> <joined-subclass name="Facility" table="facilities">
> <key column="id" />
> ...
> <set name="users" inverse="true" lazy="true">
> <key column="facility_id" />
> <one-to-many class="User" />
> </set>
> </joined-subclass>
> <!--
> - Users
> -->
> <joined-subclass name="User" table="users" dynamic-insert="true" dynamic-update="true">
> <key column="id" />
> <many-to-one name="employer" class="Entity" column="employer_id" cascade="none" />
> ...
> <set name="userAuthorities" inverse="true" cascade="all-delete-orphan">
> <key column="user_id" />
> <one-to-many class="Authority" />
> </set>
> </joined-subclass>
> </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
17 years, 9 months
[Hibernate-JIRA] Commented: (HHH-817) using projections is causing SQL query error on oracle (ORA-00904 error)
by Chris Federowicz (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
Chris Federowicz commented on HHH-817:
--------------------------------------
I have a workaround that has worked for me in basic examples.
Basically i'm using projections and the alias to bean transformer fo only load selected properties of an entity.
// Set up selected columns to load of the entity
ProjectionList projectionList = Projections.projectionList();
projectionList.add(new CustomPropertyAliasProjection("property1", "property1"));
projectionList.add(new CustomPropertyAliasProjection("property2", "property2"));
criteria.setProjection(projectionList);
criteria.setResultTransformer(new PrefixAliasToBeanResultTransformer(entityClass));
// Now I can use this without getting the ORA-00904 error
criteria.add(Restrictions.eq("property1", new Integer(1)));
Here's the class I wrote to override AliasedProjection. I can't guarantee it works in all cases. It would be great if someone from the Hibernate team can take a quick look and see if there are any potential problems that I've overlooked.
/**
* Customized projection to map a property with an alias that is intended to work-around HHH-817.
* This works in a basic situation that I've tried, but I can't guarantee it works in complex queries.
*
* This causes the alias to be bypassed in the where clause so the original column name is used.
* Some DB's don't support aliases in the where clause.
*
* http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
*
* @author Chris Federowicz
*/
public class CustomPropertyAliasProjection extends AliasedProjection {
/** Stores the property name being aliased. */
private String propertyName;
/** Stores the column name for the property in the PropertyProjection. */
private String propertyColumn;
/**
* @param propertyName the property name
* @param alias alias of the property
*/
public CustomPropertyAliasProjection(String propertyName, String alias) {
super(Projections.property(propertyName), alias);
this.propertyName = propertyName;
}
/** Default serialization ID. */
private static final long serialVersionUID = 1L;
/**
* @see org.hibernate.criterion.AliasedProjection#toSqlString(org.hibernate.Criteria, int, org.hibernate.criterion.CriteriaQuery)
*/
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
String ret = super.toSqlString(criteria, position, criteriaQuery);
// Store the property's real column for use in getColumnAliases
propertyColumn = criteriaQuery.getColumn(criteria, propertyName);
return ret;
}
/**
* Override to use the property's column if we have it (which we should).
* Hack alert: This assumes that toSqlString gets called beforehand, which seems to be the case.
*
* @see org.hibernate.criterion.AliasedProjection#getColumnAliases(java.lang.String, int)
*/
public String[] getColumnAliases(String alias, int loc) {
return propertyColumn != null ? new String[] {propertyColumn} : super.getColumnAliases(alias, loc);
}
}
> using projections is causing SQL query error on oracle (ORA-00904 error)
> ------------------------------------------------------------------------
>
> Key: HHH-817
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
> Project: Hibernate3
> Type: Bug
> Versions: 3.0.5
> Environment: Oracle 9.2.0.6, Hibernate 3.0.5, Spring Framework 1.2.2 based application working on Jakarta Tomcat 5.0.28
> Reporter: Michal Jastak
> Priority: Minor
>
>
> following java code:
> protected Entity loadEntityLightweight(Serializable entityId) throws DataAccessException {
> Criteria criteria = getSession().createCriteria(Entity.class);
> ProjectionList projectionList = Projections.projectionList();
> projectionList.add(Property.forName(BaseEntity.PROP_ID), BaseEntity.PROP_ID);
> projectionList.add(Property.forName(BaseEntity.PROP_TYPE), BaseEntity.PROP_TYPE);
> criteria.setProjection(projectionList);
> criteria.add(Restrictions.eq(BaseEntity.PROP_ID, entityId));
> criteria.setResultTransformer(new AliasToBeanResultTransformer(Entity.class));
> return (Entity) criteria.uniqueResult();
> }
> generates following SQL query:
> select this_.id as y0_, this_.type as y1_ from entities this_ left outer join facilities this_1_ on this_.id=this_1_.id left outer join users this_2_ on this_.id=this_2_.id left outer join addresses address2_ on this_.address_id=address2_.id left outer join entities entity3_ on this_2_.employer_id=entity3_.id left outer join facilities entity3_1_ on entity3_.id=entity3_1_.id left outer join users entity3_2_ on entity3_.id=entity3_2_.id where y0_=?
> y0_ = ? expression in where clause is causing a 904 error on Oracle 9:
> ORA-00904: "Y0_": invalid identifier
> hibernate dialect: org.hibernate.dialect.Oracle9Dialect
> mapping for Entity class:
> <?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 default-lazy="false" default-cascade="save-update">
>
> <class name="Entity" table="entities" mutable="true">
> <id name="id" type="java.lang.Long" unsaved-value="null">
> <generator class="sequence">
> <param name="sequence">entities_id_seq</param>
> </generator>
> </id>
> <many-to-one name="address" class="Address" column="address_id" />
> ...
> <!--
> - Facilities
> -->
> <joined-subclass name="Facility" table="facilities">
> <key column="id" />
> ...
> <set name="users" inverse="true" lazy="true">
> <key column="facility_id" />
> <one-to-many class="User" />
> </set>
> </joined-subclass>
> <!--
> - Users
> -->
> <joined-subclass name="User" table="users" dynamic-insert="true" dynamic-update="true">
> <key column="id" />
> <many-to-one name="employer" class="Entity" column="employer_id" cascade="none" />
> ...
> <set name="userAuthorities" inverse="true" cascade="all-delete-orphan">
> <key column="user_id" />
> <one-to-many class="Authority" />
> </set>
> </joined-subclass>
> </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
17 years, 9 months
[Hibernate-JIRA] Updated: (HHH-1296) Non lazy loaded List updates done in wrong order, cause exception
by Tobias Riege (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1296?page=all ]
Tobias Riege updated HHH-1296:
------------------------------
Attachment: listupdate_testcase.zip
Created two test cases failing for MySQL 5.0 and HSQL. The first case removes an element from the object's list, the second tries to add the same element to two different objects' lists. Both fail due to the unique constraint on the key of the link table as noticed by Nigel.
> Non lazy loaded List updates done in wrong order, cause exception
> -----------------------------------------------------------------
>
> Key: HHH-1296
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1296
> Project: Hibernate3
> Type: Bug
> Components: core
> Versions: 3.0.5
> Environment: Hibernate 3.0.5 - any database (checked postgres 7/8, mysql 4 & 5, db2 v8)
> NOT using lazy loading - the tx's are wrapped by session beans, so lazy loading is not allowed.
> Reporter: David Birch
> Priority: Critical
> Attachments: listupdate_testcase.zip
>
>
> The logic behind list updates is not quite right, nor was it in v2 (only now i have a DBA who won't let up...)
> The scenario is:
> a bean with list property, and the list has a number of items in it (say 4, index 0-3), an item is then removed (say item at index 2), and the bean is requested to be saved.
> From what i can see in the SQL traces, the same statements are issues whe lazy loading is on or off, they are:
> [18/12/05 19:48:50:766 EST] 00000036 SystemOut O Hibernate: delete from TGE_CLIENT_POLICY where CLIENT_ID=? and POSITION=?
> [18/12/05 19:48:50:766 EST] 00000036 SystemOut O Hibernate: update TGE_CLIENT_POLICY set POLICY_NK=? where CLIENT_ID=? and POSITION=?
> So, i can only assume (as when this fails, the row with index 1 above the removed row is nuked!), hibernate removes the item at index 3, and then copies the value of the item at index 3 onto the row for item at index 2. Fair enough but...
> When i have lazy loading off, i get DB exceptions like
> Duplicate key or integrity constraint violation message from server: "Duplicate entry '1-999999' for key 1"
> so, there is some nasty in there, which is not updating the correct row - this has happened since 2.1.8 that i know of :(
> i will try & look @ the source, but won't get a chance until after xmas...
--
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
17 years, 9 months
[Hibernate-JIRA] Created: (HBX-911) Get Default Values From DB
by Sorin Silaghi (JIRA)
Get Default Values From DB
---------------------------
Key: HBX-911
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-911
Project: Hibernate Tools
Type: Patch
Components: reverse-engineer
Versions: 3.2beta9
Environment: I worked on this patch from the TOOLS_3_2_0_BETA9 branch in SVN. I didn't actually compile the whole of hibernate-tools, I just compiled the classes I wanted to change and got the rest of the binaries from the .jar in the maven repository. If necessary I could provide a maven project that compiles the whole thing into a jar.
Reporter: Sorin Silaghi
Attachments: default-values.patch
I needed this for the project I am working on. The "client" requested this "feature"... that's for motivation. I don't think it's a great idea but it's useful.
First of all sorry for not being able to provide test cases.. I didn't had the time so I used the project I'm working on for tests.
This is how it works:
I modified JDBCReader and JDBCMetaDataDialect so that the default value is retrieved from the DB.
In JDBCBinder in the bindMeta the default value is added as a meta tag. To give user control over the process I added a couple of methods to the reveng strategy interface:
public boolean useDefaultValueOnHibernateType(String hibernateType);
- this will return true for the hibernateTypes that should have a default value(if available).
public String convertDefaultValueForColumn(TableIdentifier table, String columnName, String sqlTypeName, String hibernateTypeName, boolean isForeignKey, String value);
- and this one is used to convert the data to a form better suited for the persistence classes
I also modified the BasicPOJOClass class so that if the default value saved in the hbm is "" the initialization in the entity class will be the default constructor, for example: "new Date();".
Below is an example of how to implement a custom convertDefaultValueForColumn. Part of this could be moved to the default reveng strategy. We decided to threat fields that are foreign keys by creating an empty object with the id specified in the database and dealing with the retrieval of the rest of the data in the service layer. It actually looks better than it sounds in our case.
public String convertDefaultValueForColumn(TableIdentifier table, String columnName, String sqlTypeName, String hibernateTypeName, boolean isForeignKey, String value) {
if (isForeignKey){
if (hibernateTypeName.contains("org.kobit.ofam.service.model")){
String id;
try{
id = Long.valueOf(value).toString() + "L";
}catch(Exception e){
return null;
}
return "new " + hibernateTypeName.substring(hibernateTypeName.lastIndexOf(".") + 1)+"("+ id +")";
}
}
Class hibernateTypeClass = null;
try {
hibernateTypeClass = Class.forName(hibernateTypeName);
} catch (ClassNotFoundException e){
log.error("type not found: " + hibernateTypeName);
}
try{
if (hibernateTypeClass!=null){
if (hibernateTypeClass.equals(String.class)){
value = "\"" + value.substring(1,value.length()-1) + "\"";
return value;
}
if (hibernateTypeClass.equals(Long.class))
return Long.valueOf(value).toString() + "L";
if (hibernateTypeClass.equals(Double.class))
return Double.valueOf(value) + "D";
if (hibernateTypeClass.equals(Boolean.class))
return (Boolean.valueOf(Long.valueOf(value).longValue() > 0L)).toString();
if (hibernateTypeClass.equals(Date.class)) {
DateFormat df = DateFormat.getInstance();
return df.format(df.parse(value));
}
}
}catch(Exception e){
log.error("error converting type " + hibernateTypeName + " :" + e.getMessage() + " for value " + value);
return "";
}
return "";
}
--
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
17 years, 9 months