[Hibernate-JIRA] Commented: (HHH-1747) Issue choosing accessor method
by Peter Thiemann (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1747?page=c... ]
Peter Thiemann commented on HHH-1747:
-------------------------------------
JavaBeans-Spec says to prefer isFoo() over getFoo() for "boolean properties" - but they don't define that term....
If (like in Guilherme's example) isFoo() is just a convenience-method and there is a non-boolean setter don't we run into the danger of losing some updates when using isFoo()?
For example when the int Foo changes from 1 to 2 and isFoo() returns true in both cases?
So regardless of the Beans-specification I think getFoo() would be more adequate for internal Hibernate-use.
> Issue choosing accessor method
> ------------------------------
>
> Key: HHH-1747
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1747
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.3
> Environment: Hibernate 3.1.3, Postgresql 8.0 (but bug should be database-independent).
> Reporter: Guilherme Rios
> Priority: Minor
>
> Suppose you have a Hibernate-managed POJO that has an interface like...
> ----------
> public void setFlag(Integer flag);
> public Integer getFlag();
> public Boolean isFlag();
> ----------
> The idea here is, for whatever reason, one chooses to persist a field as an Integer, but sometimes it will be more convenient for the application to retrieve it as a Boolean (say true if its stored value != 0, false otherwise). Hibernate should use setFlag and getFlag for data persistency and retrieval, but isFlag is for app use alone; Hibernate does not and should not worry about it.
> Hibernate's behaviour is undefined in this case, when getFlag() and isFlag() both exist: the BasicPropertyAccessor will call Class.getDeclaredMethods() and choose the one of the above that comes first (http://cvs.sourceforge.net/viewcvs.py/hibernate/Hibernate3/src/org/hibern...):
> private static Method getterMethod(Class theClass, String propertyName) {
> Method[] methods = theClass.getDeclaredMethods();
> for (int i=0; i<methods.length; i++) {
> // only carry on if the method has no parameters
> if ( methods[i].getParameterTypes().length==0 ) {
> String methodName = methods[i].getName();
> // try "get"
> if ( methodName.startsWith("get") ) {
> String testStdMethod = Introspector.decapitalize( methodName.substring(3) );
> String testOldMethod = methodName.substring(3);
> if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
> return methods[i];
> }
> }
> // if not "get" then try "is"
> /*boolean isBoolean = methods[i].getReturnType().equals(Boolean.class) ||
> methods[i].getReturnType().equals(boolean.class);*/
> if ( methodName.startsWith("is") ) {
> String testStdMethod = Introspector.decapitalize( methodName.substring(2) );
> String testOldMethod = methodName.substring(2);
> if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
> return methods[i];
> }
> }
> }
> }
> return null;
> }
> API-Documentation for getDeclaredMethods() says "The elements in the array returned are not sorted and are not in any particular order", so you don't actually know which accessor will be chosen:
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getDeclaredM...
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getDeclaredM...
> Some priority should be defined for this situation, for example choosing get() over is(). If possible, Hibernate should choose which one to use based on type as defined in the associated .hbm file.
--
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, 8 months
[Hibernate-JIRA] Commented: (ANN-210) @ManyToOne not working wth @Formula
by Emmanuel Bernard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-210?page=co... ]
Emmanuel Bernard commented on ANN-210:
--------------------------------------
I tend to like Or, because for a given @JoinColumnOrFormula, you cannot use both.
OK, go for the patch that way, we will make a small warn in the javadoc, about a potential change
> @ManyToOne not working wth @Formula
> -----------------------------------
>
> Key: ANN-210
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-210
> Project: Hibernate Annotations
> Issue Type: Improvement
> Components: binder
> Affects Versions: 3.1beta7
> Environment: Hibernate 3.1, PostgreSQL 8.1.1
> Reporter: Jason Long
>
> This type of mapping fails:
> @ManyToOne
> @Formula(value="( select v_pipe_offerprice.offerprice_fk from v_pipe_offerprice where v_pipe_offerprice.id = id )")
> public OfferPrice getOfferPrice() { return offerPrice; }
> While the following mapping works as expected:
> <class name="Pipe" table="t_pipe">
> ...
> <many-to-one name="offerPrice"
> class="pipetracker.model.price.OfferPrice"
> formula="( select v_pipe_offerprice.offerprice_fk
> from v_pipe_offerprice
> where v_pipe_offerprice.id = id )"/>
> ...
> </class>
> This is not being treated as a formula because the generated SQL included a referece to the field pipe.offerprice_id which does not exsist because this is a virtual column calculated from a view.
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-1747) Issue choosing accessor method
by Christian Bauer (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1747?page=c... ]
Christian Bauer commented on HHH-1747:
--------------------------------------
The JavaBean specification says that isFoo() should be used if present and getFoo() should be ignored by the service.
> Issue choosing accessor method
> ------------------------------
>
> Key: HHH-1747
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1747
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.3
> Environment: Hibernate 3.1.3, Postgresql 8.0 (but bug should be database-independent).
> Reporter: Guilherme Rios
> Priority: Minor
>
> Suppose you have a Hibernate-managed POJO that has an interface like...
> ----------
> public void setFlag(Integer flag);
> public Integer getFlag();
> public Boolean isFlag();
> ----------
> The idea here is, for whatever reason, one chooses to persist a field as an Integer, but sometimes it will be more convenient for the application to retrieve it as a Boolean (say true if its stored value != 0, false otherwise). Hibernate should use setFlag and getFlag for data persistency and retrieval, but isFlag is for app use alone; Hibernate does not and should not worry about it.
> Hibernate's behaviour is undefined in this case, when getFlag() and isFlag() both exist: the BasicPropertyAccessor will call Class.getDeclaredMethods() and choose the one of the above that comes first (http://cvs.sourceforge.net/viewcvs.py/hibernate/Hibernate3/src/org/hibern...):
> private static Method getterMethod(Class theClass, String propertyName) {
> Method[] methods = theClass.getDeclaredMethods();
> for (int i=0; i<methods.length; i++) {
> // only carry on if the method has no parameters
> if ( methods[i].getParameterTypes().length==0 ) {
> String methodName = methods[i].getName();
> // try "get"
> if ( methodName.startsWith("get") ) {
> String testStdMethod = Introspector.decapitalize( methodName.substring(3) );
> String testOldMethod = methodName.substring(3);
> if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
> return methods[i];
> }
> }
> // if not "get" then try "is"
> /*boolean isBoolean = methods[i].getReturnType().equals(Boolean.class) ||
> methods[i].getReturnType().equals(boolean.class);*/
> if ( methodName.startsWith("is") ) {
> String testStdMethod = Introspector.decapitalize( methodName.substring(2) );
> String testOldMethod = methodName.substring(2);
> if ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) {
> return methods[i];
> }
> }
> }
> }
> return null;
> }
> API-Documentation for getDeclaredMethods() says "The elements in the array returned are not sorted and are not in any particular order", so you don't actually know which accessor will be chosen:
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getDeclaredM...
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getDeclaredM...
> Some priority should be defined for this situation, for example choosing get() over is(). If possible, Hibernate should choose which one to use based on type as defined in the associated .hbm file.
--
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, 8 months
[Hibernate-JIRA] Commented: (ANN-210) @ManyToOne not working wth @Formula
by George Harp (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-210?page=co... ]
George Harp commented on ANN-210:
---------------------------------
How about I start in my working copy:
@JoinColumnWithFormula
@JoinColumnWithFormulas
And before I send you the patch I'll check back here to see if you decided to create org.hibernate.annotations.JoinColumn instead?
Which would only mean easy refactor.
is WithFormula ok?
or do you prefer OrFormula?
> @ManyToOne not working wth @Formula
> -----------------------------------
>
> Key: ANN-210
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-210
> Project: Hibernate Annotations
> Issue Type: Improvement
> Components: binder
> Affects Versions: 3.1beta7
> Environment: Hibernate 3.1, PostgreSQL 8.1.1
> Reporter: Jason Long
>
> This type of mapping fails:
> @ManyToOne
> @Formula(value="( select v_pipe_offerprice.offerprice_fk from v_pipe_offerprice where v_pipe_offerprice.id = id )")
> public OfferPrice getOfferPrice() { return offerPrice; }
> While the following mapping works as expected:
> <class name="Pipe" table="t_pipe">
> ...
> <many-to-one name="offerPrice"
> class="pipetracker.model.price.OfferPrice"
> formula="( select v_pipe_offerprice.offerprice_fk
> from v_pipe_offerprice
> where v_pipe_offerprice.id = id )"/>
> ...
> </class>
> This is not being treated as a formula because the generated SQL included a referece to the field pipe.offerprice_id which does not exsist because this is a virtual column calculated from a view.
--
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, 8 months
[Hibernate-JIRA] Commented: (ANN-210) @ManyToOne not working wth @Formula
by Emmanuel Bernard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-210?page=co... ]
Emmanuel Bernard commented on ANN-210:
--------------------------------------
My idea was to have a
@JoinColumnOrFormulas
which contains an array of
@JoinColumnOrFormula(
joinColumn=@JoinColumn, formula=@Formula
)
The rational behind that is to be able to keep the column ordering even if formula and columns are mix and matched
I am also considering having an org.hibernate.annotations.JoinColumn, I think some information might belong here (i need ot double check)
Look for AnnotationBinder and the use of Ejb3JoinColumn and Ejb3Column, the idea is to convert the new annotations into the Ejb3*Column object. HbmBinder is the reference on how actully map using the internal model
> @ManyToOne not working wth @Formula
> -----------------------------------
>
> Key: ANN-210
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-210
> Project: Hibernate Annotations
> Issue Type: Improvement
> Components: binder
> Affects Versions: 3.1beta7
> Environment: Hibernate 3.1, PostgreSQL 8.1.1
> Reporter: Jason Long
>
> This type of mapping fails:
> @ManyToOne
> @Formula(value="( select v_pipe_offerprice.offerprice_fk from v_pipe_offerprice where v_pipe_offerprice.id = id )")
> public OfferPrice getOfferPrice() { return offerPrice; }
> While the following mapping works as expected:
> <class name="Pipe" table="t_pipe">
> ...
> <many-to-one name="offerPrice"
> class="pipetracker.model.price.OfferPrice"
> formula="( select v_pipe_offerprice.offerprice_fk
> from v_pipe_offerprice
> where v_pipe_offerprice.id = id )"/>
> ...
> </class>
> This is not being treated as a formula because the generated SQL included a referece to the field pipe.offerprice_id which does not exsist because this is a virtual column calculated from a view.
--
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, 8 months