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
hibernate-tools jira HBX-577 and ANN-774
by Ing. Arturo Frappé Muñoz
Hi all,
Finally I released a patch to solve HBX-577, it worked
as described in the book 'Java Persistance with Hibernate' but when
I run my tests I found that Annotations doesn't work as expected.
This patch is dedicated to all who loves Hibernate as well as
I.
Bug:
ANN-774
Patch:
HBX-1113
.: Arturo :.
15 years, 9 months
[Bean Validation] Same instance validated only once and determinism
by Emmanuel Bernard
I would like to revive the subject of reaching the same instance
multiple times in an object graph.
Assuming the following example
A |-> C -> B
|-> D -> B
Each arrow is an association marked as @Valid
Today, the second time an instance is reached, it is ignored.
So assuming B is invalid we can have c.b is invalid OR d.b is invalid.
I am getting more and more uncomfortable with that non-determinism.
Dhanji was not bothered arguing that in this case, a user can define
the order using groups. It's actually not possible as the same
constraint on B share the same groups definition.
An alternative proposal would look like that.
For a given object graph branch, the same instance cannot be validated
several times.
This would lead to the validation of the same object several times
provided it is in different branches
in the previous example, we would have two constraint violation reports:
- c.b is invalid
- d.b is invalid
Can you tell me on which side you are?
15 years, 9 months
Another disk crash?
by Hardy Ferentschik
Hi,
does anyone know what the problem with the Hibernate Forum is again? Since
a couple of days it is again super slow. It's pretty much impossible to
post anything.
--Hardy
15 years, 9 months
[Bean Validation] exception model
by Emmanuel Bernard
I am done with my work on the exception model.
Check the chapter copied in this email and the spec in general
(including javaDoc changes) at
http://hibernate.org/~emmanuel/validation/
Chapter 8. Exception model
Illegal arguments passed to the Bean Validation APIs generally lead to
a IllegalArgumentException (see JavaDoc for specific details). Other
exceptions raised by Bean Validation are or inherits from the runtime
exception javax.validation.ValidationException. Exception cases are
described in their respective sections but include (non exhaustive
list):
invalid constraint definitions (missing mandatory elements, illegal
composition cycle, illegal parameter overriding, etc)
invalid constraint declarations (ConstraintValidator implementation
matching failure, etc)
invalid group definition (circularity)
invalid Default group redefinition for classes (missing class group etc)
error when retrieving, initializing, executing ConstraintValidators
error when parsing the XML configuration or mappings
multiple XML configuration files found
missing expected provider or no default provider found
missing no-arg constructors on extension implementations described in
the XML configuration file
same entity described more than once across the XML mapping files
same property or field described more than once for a given entity in
the XML mapping files
class, field or getter declared in XML mapping files but not found
illegal XML constraint definition
illegal XML constraint declaration
exception raised either at initialization time or execution time by
any of the extension interfaces
Each of these error cases lead to a ValidationException or a subclass
of ValidationException (see following subsections).
Every (runtime) exception raised either at initialization time or
execution time by any of the extension interfaces
(ConstraintValidator, ConstraintValidatorFactory,
MessageInterpolator,TraversableResolver, ValidationProviderResolver)
is wrapped in a ValidationException.
If a constraint definition or constraint declaration is invalid for a
given class, the metadata API should raise the according exception.
8.1. Error report: ConstraintViolationException
Some frameworks or applications need to convey the results of a
validation. It is an exception case if the validation returns
constraint violation and a Java exception is raised.
Bean Validation provides a reference exception for such cases.
Frameworks and applications are encouraged to use
ConstraintViolationException as opposed to a custom exception to
increase consistency of the Java platform. The exception can be raised
directly or wrapped into the framework or application specific mother
exception.
/**
* Report the result of constraint violations
*
* @author Emmanuel Bernard
*/
public class ConstraintViolationException extends ValidationException {
/**
* Creates a constraint violation report
*
* @param message error message
* @param constraintViolations Set of ConstraintViolation
*/
public ConstraintViolationException(String message,
Set<ConstraintViolation> constraintViolations) {
[...]
}
/**
* Creates a constraint violation report
*
* @param constraintViolations Set of ConstraintViolation
*/
public ConstraintViolationException(Set<ConstraintViolation>
constraintViolations) {
[...]
}
/**
* Set of constraint violations reported during a validation
*
* @return Set of CosntraintViolation
*/
public Set<ConstraintViolation> getConstraintViolations() {
[...]
}
}
The ConstraintViolationException carries a set of ConstraintViolation.
Note
Bean Validation never raises this exception itself. Other frameworks
like Java Persistence 2 do.
8.2. Constraint definition: ConstraintDefinitionException
If a constraint definition does not respect the Bean Validation rules
or is inconsistent, a ConstraintDefinitionException is raised.
This exception can be raised during validation or when the metadata
model for the class hosting this constraint is requested.
Note
These exception cases can be determined at compile time by a tool such
as an annotation processor.
8.3. Constraint declaration: ConstraintDeclarationException and
UnexpectedTypeException
When a constraint declaration is illegal,
ConstraintDeclarationException is raised.
When the return type of a property cannot be processed for a given
constraint, an UnexpectedTypeException is raised. This problem
typically arise when either no ConstraintValidator or too many
ConstraintValidators match the return type (see Section 3.5.3,
“ConstraintValidator resolution algorithm”).
This exception can be raised during validation or when the metadata
model for the class hosting this constraint is requested.
Note
These exception cases can be determined at compile time by a tool such
as an annotation processor.
8.4. Group definition: GroupDefinitionException
When a group definition is illegal, GroupDefinitionException is
raised. This typically arises when a cyclic group dependency is
discovered.
Note
These exception cases can generally be determined at compile time by a
tool such as an annotation processor.
15 years, 9 months
Compilation error
by Alaa Mohsen
Hello guys,
We continuously update our copy of Hibernate Validator/Bean Validator
API from the SVN. Our last update was a couple of minutes ago, and the
project doesn't compile because
org.hibernate.validation.engine.ConstraintTree refers to
org.hibernate.validation.AmbiguousConstraintUsageException and
javax.validation.UnexpectedTypeException that are not present.
Regards,
Alaa Nassef
15 years, 9 months