[Hibernate-JIRA] Created: (HHH-5265) @Formula adds a this_. prefix to an SQL function
by Matthias Bosshard (JIRA)
@Formula adds a this_. prefix to an SQL function
------------------------------------------------
Key: HHH-5265
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5265
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core
Affects Versions: 3.5.2
Environment: Hibernate 3.5.2, with a SQL Anywhere 10 and the org.hibernate.dialect.SybaseDialect
Reporter: Matthias Bosshard
With Hibernate 3.5.2 the ISNULL/COALESCE SQL statement in the following @Formula is prefixed with a this_. An so its no valid SQL.
The annotation:
@Formula( "(SELECT ISNULL ( (SELECT 1 WHERE EXISTS (SELECT * FROM org.usertable as user WHERE user.user_id = user_id)), 0))" )
The SQL part for this formula:
(SELECT *this_.ISNULL* ( (SELECT 1 WHERE EXISTS (SELECT * FROM org.usertable as user WHERE user.user_id = this_.user_id)), 0)) as formula8_1_,
-> thats invalid SQL
In Hibernate 3.5.1 the SQL is pretty the same, but without this_. before ISNULL.
(SELECT *ISNULL* ( (SELECT 1 WHERE EXISTS (SELECT * FROM org.usertable as user WHERE user.user_id = this_.user_id)), 0)) as formula8_1_,
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-3824) OneToOne join by Non-primary key column throws PropertyAccessException when join column is String
by sathish (JIRA)
OneToOne join by Non-primary key column throws PropertyAccessException when join column is String
-------------------------------------------------------------------------------------------------
Key: HHH-3824
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3824
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria, query-hql
Affects Versions: 3.3.1
Environment: Microsoft SQL server 2005, Hibernate 3.3.1
Reporter: sathish
Attachments: trace.txt
When i try to join 2 entities by OneToOne using a Non-primary key column, it throws the following exception:
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.xxx.domain.Inventory.sku
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.inwk.estore.server.domain.Inventory.sku to java.lang.Integer
[Full stacktrace attached]
sku is the Non-primary key String join column by which im trying to do a OneToOne join between Item and Inventory entity.
Apparently its trying to interpret Sku as an Integer column. Adding columnDefinition as VARCHAR/String doesn't help either
Mappings for Item and Inventory are below:
class Item{
@Id
Long id;
@Column
String sku;
//some more properties
@OneToOne(optional = true)
@JoinColumn(name = "sku", referencedColumnName = "sku", insertable = false, updatable = false)
Inventory inventory;
}
class Inventory{
@Id
Long id
@Column
String sku
@Column
Long quantity;
}
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5736) Problem with "not" function of CriteriaBuilder
by Vyacheslav Dimitrov (JIRA)
Problem with "not" function of CriteriaBuilder
----------------------------------------------
Key: HHH-5736
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5736
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0
Reporter: Vyacheslav Dimitrov
Let us suppose that we have entity "Floor" with property of "number".
Then we want to create query with the help of Criteria API: we want to get all floors and exclude floors with number of 2 and 3. Let us suppose that our code is:
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cr = builder.createTupleQuery();
Root<Floor> root = cr.from(Floor.class);
cr.multiselect(root);
Predicate p1 = builder.equal(root.get("number"), new Integer(2));
Predicate p2 = builder.equal(root.get("number"), new Integer(3));
cr.where(builder.not(builder.or(p1, p2)));
So we get query:
[java] Hibernate:
[java] select
[java] floor0_.beanId as beanId0_,
[java] floor0_.building_beanId as building3_1_,
[java] floor0_.number as number1_
[java] from
[java] Floor floor0_
[java] where
[java] floor0_.number=2
[java] or floor0_.number=3
This query is wrong. Function "not" doesn't work.
But for query "get all floors and exlclude floor with number 2" this code works:
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cr = builder.createTupleQuery();
Root<ru.petrsu.nest.son.Floor> root = cr.from(ru.petrsu.nest.son.Floor.class);
cr.multiselect(root);
Predicate p = builder.equal(root.get("number"), new Integer(2));
cr.where(builder.not(p));
We get correct query:
[java] Hibernate:
[java] select
[java] floor0_.beanId as beanId0_,
[java] floor0_.building_beanId as building3_1_,
[java] floor0_.number as number1_
[java] from
[java] Floor floor0_
[java] where
[java] floor0_.number<>3
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5136) map-key-column is broken
by Harald Wellmann (JIRA)
map-key-column is broken
------------------------
Key: HHH-5136
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5136
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.1
Environment: Hibernate 3.5.1, PostgreSQL 8.4.3
Reporter: Harald Wellmann
Priority: Critical
I have an entity with a Map<String, Embeddable> with unexpected behaviour. The problem is that annotation mappings and the equivalent XML mappings yield different results. (For brevity, I'm leaving out the getters and setters and the SQL constraints in the following examples.)
Here is my Embeddable:
{code:java}
@Embeddable
public class LocalizedString
{
private String language;
private String text;
}
{code}
And this is the containing entity:
{code:java}
@Entity
public class Amenity
{
@Id
@Column(name = "amenity_id")
@GeneratedValue
private long id;
@ElementCollection
@CollectionTable(name = "amenity_name", joinColumns = @JoinColumn(name = "amenity_id"))
@MapKeyColumn(name = "language_map_key")
private Map<String, LocalizedString> names = new HashMap<String, LocalizedString>();
}
{code}
Hibernate generates the following collection table:
{code:sql}
CREATE TABLE amenity_name
(
amenity_id bigint NOT NULL,
"language" character varying(255),
"text" character varying(255),
language_map_key character varying(255) NOT NULL
)
{code}
Now when replacing the annotations by the following XML mapping
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<entity class="Amenity">
<attributes>
<id name="id">
<column name="amenity_id"/>
<generated-value />
</id>
<element-collection name="names">
<map-key-column name="language_map_key" />
<collection-table name="amenity_name">
<join-column name="amenity_id" referenced-column-name="amenity_id"/>
</collection-table>
</element-collection>
</attributes>
</entity>
<embeddable class="LocalizedString">
<attributes>
<basic name="language"></basic>
<basic name="text"></basic>
</attributes>
</embeddable>
</entity-mappings>
{code}
the generated SQL looks like this:
{code:sql}
CREATE TABLE amenity_names
(
amenity_amenity_id bigint NOT NULL,
"language" character varying(255),
"text" character varying(255),
names_key character varying(255) NOT NULL
)
{code}
It seems that the map-key-column and collection-table settings are simply ignored.
Another question: The column language_map_key is actually redundant, I would like to use the language column as map key instead. The JPA 2.0 spec is a bit vague on this case. When the map value is an entity, @MapKey can be used to select a property of the entity value as map key, but it is not clear to me whether the spec supports supressing the separate key column when the map value is an embeddable.
I tried using @MapKeyColumn(name="language"), but then Hibernate complained about a duplicate column.
Eclipselink (the version contained in Glassfish v3) accepts this usage and suppresses the duplicate column, i.e. the join table has the form
{code:sql}
CREATE TABLE amenity_name
(
amenity_id bigint NOT NULL,
"language" character varying(255),
"text" character varying(255)
)
{code}
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5722) Method annotated with @PreUpdade is not called
by Oleksandr Alesinskyy (JIRA)
Method annotated with @PreUpdade is not called
----------------------------------------------
Key: HHH-5722
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5722
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.6.0
Environment: Java 1.6.0_21, Windows and Linux
Reporter: Oleksandr Alesinskyy
I have a class with methods annotated @PostLoad, @PrePersist, and @PreUpdate as below:
{code:title=Snippet}
@Transient
private B2BCustomerKeyPo b2BCustomerKey;
@Embedded
@AttributeOverrides( { @AttributeOverride(name = "username", column = @Column(name = "APPLICATION_NAME")),
@AttributeOverride(name = "b2BCustomerName", column = @Column(name = "B2BCUSTOMER_NAME")) })
private UserKeyPo applicationKey;
...
@SuppressWarnings("unused")
@PostLoad
private void postLoad() {
if (applicationKey != null) {
if (applicationKey.getB2BCustomerName() != null) {
b2BCustomerKey = new B2BCustomerKeyPo(applicationKey.getB2BCustomerName());
}
if (applicationKey.getUsername() == null) applicationKey = null;
}
}
@SuppressWarnings("unused")
@PrePersist
private void prePersist() {
if (b2BCustomerKey != null) {
if (applicationKey != null) {
if (!b2BCustomerKey.equals(new B2BCustomerKeyPo(applicationKey.getB2BCustomerName()))) {
final String msg =
String
.format(
"B2B customer [%s] of the product does not match the Application of the product [%s/%s]",
b2BCustomerKey.getName(), applicationKey.getB2BCustomerName(),
applicationKey.getUsername());
throw new IllegalStateException(msg);
}
} else {
applicationKey = new UserKeyPo(b2BCustomerKey.getName(), null);
}
}
}
@SuppressWarnings("unused")
@PreUpdate
private void preUpdate() {
throw new RuntimeException("§TEST§");
}
{code}
prePersist and postLoad methods work as expected but preUpdate method is not called at all - while updated fields are dutifully written into DB (they never would if preUopdate will be called).
The code manipulating the object is as below:
{code:title=Snippet2}
ProductPo productPoOld = readProductPo(input.getProduct().getProductKey().getExternalProductKey());
...
B2BCustomerKey b2bCustomerKey = productNew.getB2BCustomerKey();
productPoOld.setB2BCustomerKey(mappingHelper.mapObject(productNew.getB2BCustomerKey(),
B2BCustomerKeyPo.class));
LOG.debug(productPoOld.getB2BCustomerKey());
// @PreUpdate method is not called regardless if flush is present below or not
productDao.flush();
{code}
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-4581) Embedded objects in criteria API does not work
by Jaroslaw Lewandowski (JIRA)
Embedded objects in criteria API does not work
----------------------------------------------
Key: HHH-4581
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4581
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.5.0-Beta-2
Reporter: Jaroslaw Lewandowski
It not possible to use Embedded attribute in Criteria API. E.g. having the following entity
@Entity
class Client {
@Embedded
private Name name;
}
@Embeddable
public class Name implements Serializable {
@Basic
private String firstName;
@Basic
private String lastName;
}
The following throws an exception
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ClientCard> cq = cb.createQuery(Client.class);
Root<ClientCard> root = cq.from(ClientCard.class);
cq.where(cb.equal(root.get(Client_.name).get(Name_.firstName)), "blah");
em.createQuery(cq).getResultList();
Saying that Name is not managed entity:
Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.phorest.memento.server.domain.Name
at org.hibernate.ejb.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:171)
at org.hibernate.ejb.criteria.JoinImpl.<init>(JoinImpl.java:54)
at org.hibernate.ejb.criteria.FromImpl.constructJoin(FromImpl.java:193)
at org.hibernate.ejb.criteria.FromImpl.join(FromImpl.java:176)
at org.hibernate.ejb.criteria.FromImpl.join(FromImpl.java:169)
at org.hibernate.ejb.criteria.FromImpl.get(FromImpl.java:559)
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5751) MappingException: using @Column in Embedded ID classes fail when also used in an @JoinColumn in the entity class
by Karsten Wutzke (JIRA)
MappingException: using @Column in Embedded ID classes fail when also used in an @JoinColumn in the entity class
----------------------------------------------------------------------------------------------------------------
Key: HHH-5751
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5751
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, metamodel
Affects Versions: 3.6.0
Environment: Hibernate 3.6, JavaSE, HSQLDB, Ant
Reporter: Karsten Wutzke
Priority: Critical
Attachments: zips-hib-embeddedid-column-broken.zip
Here's the DB design (DDL):
CREATE TABLE Countries
(
iso_code CHAR(2) NOT NULL,
name VARCHAR(50) NOT NULL,
PRIMARY KEY (iso_code)
);
CREATE TABLE Zips
(
country_code CHAR(2) NOT NULL,
code VARCHAR(10) NOT NULL,
PRIMARY KEY (country_code, code),
FOREIGN KEY (country_code) REFERENCES Countries (iso_code)
);
Here's the Zip class + composite primary key class:
@Entity
@Table(name = "Zips")
public class Zip implements Serializable
{
@EmbeddedId
private ZipId embeddedId;
@ManyToOne
@JoinColumn(name = "country_code", referencedColumnName = "iso_code")
private Country country = null;
...
}
@Embeddable
public class ZipId implements Serializable
{
@Column(name = "country_code", insertable = false, updatable = false)
private String countryCode;
@Column(name = "code")
private String code;
...
}
Hibernate stack trace:
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: zips] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.zips.Main.main(Main.java:27)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: tld.zips.model.Zip column: country_code (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:675)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:697)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:719)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:473)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1332)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
... 4 more
The problem here is the @Column on the @Embeddable composite primary key class. country_code is mapped as read-only (insertable = false, updatable = false) in the composite primary key class. The above syntax is JPA-compatible. Clearly, there's no other clean way where to put the @Column annotations but into the @Embeddable class. It's incomprehensible why this doesn't work. @Embeddable classes allow @Basic, @Column, @Enumerated, @Temporal, @Lob, and @Embedded on its columns, so this should work.
The exception vanishes when putting the insertable = false, updatable = false on the @JoinColumn, but this is not what I want. I prefer my associations to be writable...
The above syntax works perfectly with EclipseLink!
--
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
13 years, 6 months