[Hibernate-JIRA] Created: (HHH-3993) one-to-one with composite-id must have common CompositeId class
by Sandeep Vaid (JIRA)
one-to-one with composite-id must have common CompositeId class
---------------------------------------------------------------
Key: HHH-3993
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3993
Project: Hibernate Core
Issue Type: Improvement
Affects Versions: 3.2.6
Reporter: Sandeep Vaid
I have one-to-one relationship between Product and Product-Id..
I have Product (PId, PDesc) as composite-key
I have ProductBasic (ProductId, ProductDesc) as composite-Key
Case 1: I created one Composite class which is common for both Product and ProductBasic..
class CompProductRelated{
string pid;
string pdesc;
}
then try to fetch Product.. It worked !!!
Case 2: If i create seperate Composite class for Product & ProductBasic viz. CompProduct and CompProductBasic respectively as :
class CompProduct{
string productId;
string productDesc;
}
and not if i define the mapping accordingly as:
In Product.hbm.xml
<composite-id name="compProduct" class="CompProduct">
<key-property name="pid" type="string" column="PRODUCTID" length="10"></key-property>
<key-property name="desc" type="string" column="DESC" length="10"></key-property>
</composite-id>
In ProductBasic.hbm.xml
<composite-id name="compProductBasic" class="CompProductBasic">
<key-property name="productId" column="PRODUCTID" type="string" length="10"/>
<key-property name="productDesc" column="DESC1" type="string" length="10"/>
</composite-id>
Now while fetching Product (and internally it will fetch ProductBasic), it gives the following exception:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class model.CompProductBasic, got class model.CompProduct
So the only approach for one-to-one with composite-id is to have a common compositeId class..
The link http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#map...
recommends 3 solutions (3rd being to have a common compositeId class) but as per my understanding 1st and 2nd approach will give exception for one-to-one with composite-id ...
I think this hibenate restriction (of having common CompositeId class for one-to-one relationship) is not good as it puts a constraint on how domain model (java) should be which could not be possible everytime in legacy applications..
--
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
15 years, 6 months
[Hibernate-JIRA] Created: (HBX-1127) import.sql doesn't work with scalar variables in SQL 2005
by Joseph Miller (JIRA)
import.sql doesn't work with scalar variables in SQL 2005
---------------------------------------------------------
Key: HBX-1127
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1127
Project: Hibernate Tools
Issue Type: Bug
Environment: Hibernate 3.3.1.GA, Microsoft SQL Server 2005
Reporter: Joseph Miller
I have in my import.sql the following (which works fine when run directly against the server):
declare @today DATETIME;
set @today = cast( floor( cast( getdate() as decimal(12,5))) as datetime);
(The same error also happens when I use 'select @today = cast( .... )' )
However, when the import.sql is run by Hibernate at startup I get:
12:55:33,099 ERROR [SchemaExport] schema export unsuccessful
org.hibernate.JDBCException: Error during import script execution at line 2
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:332)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:264)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:343)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor1602.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
....
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
Caused by: java.sql.SQLException: Must declare the scalar variable "@today".
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:723)
at net.sourceforge.jtds.jdbc.JtdsStatement.execute(JtdsStatement.java:1157)
at org.jboss.resource.adapter.jdbc.WrappedStatement.execute(WrappedStatement.java:84)
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:328)
... 105 more
--
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
15 years, 6 months
[Hibernate-JIRA] Created: (HV-170) Refactor the group sequence expansion and take the default sequence expansion of the validated entity into considertation
by Hardy Ferentschik (JIRA)
Refactor the group sequence expansion and take the default sequence expansion of the validated entity into considertation
-------------------------------------------------------------------------------------------------------------------------
Key: HV-170
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-170
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.0.0.Beta1
Reporter: Hardy Ferentschik
Assignee: Hardy Ferentschik
Fix For: 4.0.0.Beta2
At the moment the group sequence expansion does not take into consideration any default group re-definition of the validated entity. However, it should
>From IRC:
epbernard: say I have Complete -> Default, Heavy that's a regular sequence
epbernard: then on class A, I have @GS(Heavy, A)
epbernard: When expanding I have Heavy, A, Heavy => exception
hardy: epbernard: so you mean validator( aEntity, Complete.class)
epbernard: We have Default before Heavy
epbernard: and Default is defined as Heavy before A
epbernard: To the sequence is Heavy A Heavy
epbernard: ah hold on let me think
hardy: right
hardy: so we actually really HAVE to pass the entity to the GroupChainGenerator
epbernard: ah yes so let's assume that < means before ok?
epbernard: hardy:
sebersole: why dont you guiys get a room?
epbernard: Default < Heavy means Heavy < Heavy (accepted by the spec) and A < Heavy
epbernard: but we also have Heavy < A (the defainintion of Default)
epbernard: hence the inconsistency
--
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
15 years, 6 months
[Hibernate-JIRA] Created: (HHH-2983) Properties of a Map key not consistently populated before being put into the Map
by Dobes Vandermeer (JIRA)
Properties of a Map key not consistently populated before being put into the Map
--------------------------------------------------------------------------------
Key: HHH-2983
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2983
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5
Environment: Glassfish v2 b58, PostgreSQL 8.2, running in Windows XP
Reporter: Dobes Vandermeer
I'm getting weird behavior where my map correctly has two entries when fetched as part of a list, and only one entry when I fetch it using EntityManager.get().
Here's an abbreviated version of the mapping for the class that contains the Map:
@Entity(name="Account")
public class Account implements Comparable<Account>, SecurityChecks {
private Long id;
private Map<Currency, Balance> balances = new HashMap<Currency, Balance>(); // Current balance in each currency
public Account() {
}
@Id @GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade={CascadeType.ALL}, mappedBy="account")
@MapKey(name="currency")
public Map<Currency, Balance> getBalances() {
return balances;
}
public void setBalances(Map<Currency, Balance> balances) {
this.balances = balances;
}
}
And the class that it contains:
@Entity(name="Balance")
@Table(uniqueConstraints={@UniqueConstraint(columnNames={ "account_id", "currency_id" })})
public class Balance implements SecurityChecks {
private Long id;
private Account account;
private Currency currency;
private long amount;
@ManyToOne(cascade=CascadeType.PERSIST, optional=false)
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
@Column(nullable=false)
public long getAmount() {
return amount;
}
public void setAmount(long amount) {
this.amount = amount;
}
@ManyToOne(cascade=CascadeType.PERSIST, optional=false)
@JoinColumn(name="currency_id")
public Currency getCurrency() {
return currency;
}
public void setCurrency(Currency currency) {
this.currency = currency;
}
@Id @GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
And a class that has a list of Accounts:
@Entity(name="Business")
public class Business implements SecurityChecks {
private Long id;
private String name;
private List<Account> accounts = new ArrayList<Account>();
@Id @GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(mappedBy="business", cascade={CascadeType.ALL})
public List<Account> getAccounts() {
return accounts;
}
public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
@Column(nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Here's the definition of Currency:
package com.habitsoft.books.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import com.habitsoft.books.service.client.CurrencyFormatter;
@Entity(name="Currency")
public class Currency implements Comparable<Currency> {
private Long id;
private String currencyCode;
private String name;
private String prefix = "";
private String suffix = "";
private int decimalPlaces;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((getCurrencyCode() == null) ? 0 : getCurrencyCode().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Currency other = (Currency) obj;
if (getCurrencyCode() == null) {
if (other.getCurrencyCode() != null)
return false;
} else if (!getCurrencyCode().equals(other.getCurrencyCode()))
return false;
return true;
}
public int compareTo(Currency obj) {
if (this == obj)
return 0;
if (obj == null)
return -1;
final Currency other = (Currency) obj;
return getCurrencyCode().compareTo(other.getCurrencyCode());
}
public String getCurrencyCode() {
return currencyCode;
}
public void setCurrencyCode(String currencyCode) {
this.currencyCode = currencyCode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Here's a line of code I use to fetch the Account directly:
return em.find(Account.class, accountId);
Here's how I fetch the list of accounts for a business:
Business business = em.find(Business.class, businessId);
return business.getAccounts().subList(offset, offset+limit);
What is very, very odd to me is that the Accounts returned by the first form have just a single Balance instance in the map, when there should be two, whereas the ones returned by the second form have both entries I'm expecting.
Hibernate prints the following SQL queries:
Hibernate: select account0_.id as id270_0_, account0_.business_id as business5_270_0_, account0_.description as descript2_270_0_, account0_.name as name270_0_, account0_.type as type270_0_ from Account account0_ where account0_.id=?
Hibernate: select balances0_.account_id as account3_2_, balances0_.id as id2_, balances0_.currency_id as formula5_2_, balances0_.id as id271_1_, balances0_.account_id as account3_271_1_, balances0_.amount as amount271_1_, balances0_.currency_id as currency4_271_1_, currency1_.id as id275_0_, currency1_.currencyCode as currency2_275_0_, currency1_.decimalPlaces as decimalP3_275_0_, currency1_.name as name275_0_, currency1_.prefix as prefix275_0_, currency1_.suffix as suffix275_0_ from Balance balances0_ inner join Currency currency1_ on balances0_.currency_id=currency1_.id where balances0_.account_id=?
If I execute these queries against the database manually, the correct number of results is returned, so it seems likely that hibernate is generating the correct query, but then populating the map incorrectly.
I took a guess that hashCode() and equals() in Currency were the most likely cause of the issue and indeed if I change them to use id instead of currencyCode the problem goes away.
So, for some odd reason hibernate is populating the id field and not the other fields, and then putting it into the Map, but only when the object is fetched directly. This seems to point to some inconsistency in the way hibernate is initializing the objects and maps, somewhere.
The workaround is to not use any fields except id in hashCode() and equals() for an entity used as a map key, and to ensure you call persist() on the key objects before putting them into the map. This seems like a reasonable constraint to me, but it would be nice if the behavior was more consistent to avoid excessive head-scratching.
--
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
15 years, 6 months
[Hibernate-JIRA] Created: (HHH-3990) Bulk update statements do not use default schema in generated SQL
by hard hat (JIRA)
Bulk update statements do not use default schema in generated SQL
-----------------------------------------------------------------
Key: HHH-3990
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3990
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1GA
Oracle 10g
Reporter: hard hat
Priority: Critical
When setting the hibernate.default_schema property in hibernate.cfg, the schema is not used when executing buld (hql) update statements. You can test this easily with any existing hibernate mapping + database:
Create a second database user, grant select & update rights for the tables in your existing database to that user. Modify your hibernate.cfg to use the new user and set the default schema to the new user. Now, your application should work just as before, except for any bulk updates. You can now try to make a bulk update, for exampe:
query = session.createQuery("update versioned Person p SET p.name = :name where p.id = :id");
query.setString("name", "Jack");
query.setLong("id", 42);
query.executeUpdate();
This fails with TABLE NOT EXIST error, because the generated SQL does not have the defined default schema as prefix.
--
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
15 years, 6 months
[Hibernate-JIRA] Created: (HHH-3989) MYSQLDialect should not use row-value constructor syntax for UPDATE statements
by Stephen Henderson (JIRA)
MYSQLDialect should not use row-value constructor syntax for UPDATE statements
------------------------------------------------------------------------------
Key: HHH-3989
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3989
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Reporter: Stephen Henderson
Priority: Minor
The MYSQLDialect (and subclasses) returns true for {{supportsRowValueConstructorSyntax()}}, but this only seems to apply for SELECT statements. For update statements row-value syntax returns an sql syntax error.
i.e. "SELECT * FROM myTable WHERE (a,b,c) = (?,?,?)" works ok, but "UPDATE myTable SET (a,b,c) = (?,?,?)" gives a syntax error.
In hibernate code this seems to mostly affect updating embeddable columns through update hql statements.e.g. "update myEntity set address = :address" where address is an instance of an embeddable type.
For example, if I have a simple embeddable address like:
{code}
@Embeddable
public class Address {
String street;
String county;
String postCode;
...
{code}
Then if I attempt to update the address column for an entity like this:
{code}
Address a = new Address();
a.setCounty("my county");
a.setPostCode("MY1 PC1");
a.setStreet("my street");
Query qry = session.createQuery("update Customer c set c.address = :address where c.customerId=1");
qry.setParameter("address", a);
qry.executeUpdate();
{code}
I get the following error:
{noformat}
org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:110)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:421)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:283)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1169)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:117)
at core.sql.mysql.BulkInsertTest.testEntityRowColumn(BulkInsertTest.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' postCode, street=('my county', 'MY1 PC1', 'my street') where customerId=1' at line 1
Query being executed when exception was thrown:
update Customer set county, postCode, street=('my county', 'MY1 PC1', 'my street') where customerId=1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at project.tripplanner.database.hibernate.HibernatePreparedStatementWrapper.executeUpdate(HibernatePreparedStatementWrapper.java:164)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:101)
... 27 more
{noformat}
I tried extending the MYSQLDialect classes and overriding {{supportsRowValueConstructorSyntax()}} to return false, but this caused other errors.
--
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
15 years, 6 months