Solution: Anyone aware of an implementation of SessionBroker on top of JPA or Hibernate API?
by Sebastien Tardif
I have coded a Session Broker framework. It is designed to also support
Hibernate specific APIs by deriving from neutral classes.
Please take a look at:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=260258
From: Sebastien Tardif
Sent: Monday, April 20, 2009 3:27 PM
To: 'hibernate-users(a)lists.jboss.org'
Subject: Anyone aware of an implementation of SessionBroker on top of
JPA or Hibernate API?
Anyone aware of an implementation of SessionBroker on top of JPA or
Hibernate API?
I mean by SessionBroker, an encapsulation of the fact that 2
EntityManager potentially pointing to 2 different databases are
involved. So that the client is coded like just one EntityManager is
used. Similar to:
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/b136
98/oracle/toplink/sessionbroker/SessionBroker.html
This is having for constraint that each EntityManager do not reference
the same classes so that query like below can be redirected to the right
EntityManager transparently because can lookup the right EntityManager
using the class:
* em.createNativeQuery("select id from Mag, Mag.class")
* em.createQuery("from Category c where xyz");
14 years, 8 months
postgres @GeneratedValue
by Christine Karman
We're having an issue with generated primary keys in a postgres
database. We use Seam, JbossAS, JPA, Hibernate. In a class named Address
we have a "long id" with the following annotations:
@Id
@SequenceGenerator(name = "ADDRESS_SEQ", sequenceName =
"address_id_seq", allocationSize = 1, initialValue =51)
@GeneratedValue(generator = "ADDRESS_SEQ")
private long id;
This works perfectly well, until we decided to seed the database with an
import script. It seems like Hibernate does not see the imported
addresses. The address class in Postgres has a field 'id' of type
"BigInt". But in order to have autogenerated keys, it should be 'serial'.
Our solution was to change the annotations to
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
Now, I'm happy that we found a solution, but I don't understand why this
works. Also, shouldn't Hibernate always make @GeneratedValue fields of
type 'serial'?
From what I found googling, this seems to be a problem that only occurs
when you use Postgres.
dagdag
Christine
--
*BiD **Network*
Preparing emerging market entrepreneurs for investors
www.bidnetwork.org <http://www.bidnetwork.org/>
*Come to the SME investor marketplace on June 2nd**
--> smeforum2010.org <http://smeforum2010.org/>*
14 years, 8 months
[ANN]VTD-XML 2.8
by Jimmy Zhang
VTD-XML 2.8 has been released. Please visit https://sourceforge.net/projects/vtd-xml/files/ to download the latest version.
a.. Expansion of Core VTD-XML API
a.. VTDGen adds support for capturing white spaces
b.. VTDNav adds support for suport for getContentFragment(), recoverNode() and cloneNav()
c.. XMLModifier adds support for update and reparse feature
d.. AutoPilot adds support for retrieving all attributes
e.. BookMark is also enhanced.
b.. Expansion of Extended VTD-XML API
a.. Add content extraction ability to extended VTD-XML
b.. VTDNavHuge now can call getElementFragment() and getElementFragmentNs()
c.. VTDGenHuge adds support for capturing white spaces
c.. XPath
a.. Adds comment and processing instruction support for nodes, and performance enhancement
b.. Adds namespace axis support .
c.. Adds round-half-to-even()
d.. A number of bug fixes and code enhancement
14 years, 8 months
Out of order cascade persist
by Loreno Oliveira
Hi there,
I'm facing a weird behavior of hibernate.
Trying to illustrate: I have three entities, say A, B, and C. In my scheme,
A has one B which has one C, which has a reference to the parent A.
This is my code:
@Entity
@Table(name = "ASSOCIADOS")
public class Associado implements Serializable {
@OneToOne( cascade=CascadeType.ALL )
@JoinColumn( name="idFiliacao" )
private Filiacao filiacao;
}
@Entity
@Table(name = "FILIACOES")
public class Filiacao implements Serializable {
@OneToOne( cascade=CascadeType.ALL )
@JoinColumn(name="idDependentePai" )
private Dependente pai;
}
@Entity
@Table(name = "DEPENDENTES")
public class Dependente implements Serializable {
@ManyToOne
@JoinColumn( name="idAssociado" )
private Associado titular;
}
My problem is that when I try to persist a fully configured Associado (with
a Filiation that has a Dependente which, in turn, has a reference to the
parent Associado) the inserts generated by Hibernate seem to be out of
order. I mean, first Hibernate tries to insert the Dependente entity, which
has a reference to the primary key of Associado. But, at this point,
Associado was not inserted yet. So, I'm getting this error:
Caused by: java.sql.BatchUpdateException: Column 'idAssociado' cannot be
null
And this is the SQL generated by hibernate:
insert into DEPENDENTES (nome, nascimento, idParentesco, idAssociado,
beneficiarioPeculio, dependentePlanoSaude, id) values ('Nome Qualquer', '',
3, '', 'false', 'false', 6900)
Right after the em.persist (I'm using Hibernate JPA) I stop the thread in
the debugger and I can see that All the objects got an ID assigned. However,
during the commit I'm getting this error.
Does anyone have any hint about this?
Thanks in advance!
Loreno
14 years, 8 months
Hibernate 3.5 + JPA + HSQLDB embedded (or in process)
by Amirouche BOUBEKKI
Héllo,
I have some troubles getting hibernate 3.5 working properly with HSQLDB (in
process mode), I got same issues with SQLite [1] but everything works as
excepted with mysql.
I'm new to hibernate and all this java art so forgive me if I make big
errors.
The problem is each time I start my app which creates and populates serveral
table, the next run the db seems empty, and I have to fill it again.
I've setup a project using the 3.5 version of hibernate using JPA/EJB. I've
setup a persistence unit (thanks to netbeans) automatically generating the
presistence.xml needed for the emf setup
persistence.xml
<code>
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PMMPU2" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.Extrait</class>
<class>model.Mot</class>
<class>model.Prefixe</class>
<class>model.Suffixe</class>
<class>model.Texte</class>
<properties>
<property name="hibernate.connection.username" value="SA"/>
<property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url"
value="jdbc:hsqldb:file:db/base;shutdown=true"/>
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
</code> http://java.pastebin.com/LFfB0gSt
I have also a HibernateUtil which helps me with emf & em:
<code>
public class HibernateUtil {
private static EntityManagerFactory emf = null;
private static EntityManager em = null;
public static EntityManagerFactory getEmf()
{
if(emf == null)
{
Map<String, Object> configOverrides = new
HashMap<String, Object>();
// configOverrides.put("hibernate.hbm2ddl.auto", "update");
configOverrides.put("hibernate.show_sql", "true");
emf = Persistence.createEntityManagerFactory("PMMPU2",
configOverrides);
}
return emf;
}
public static EntityManager getEm()
{
if(em == null)
em = getEmf().createEntityManager();
return em;
}
}
</code> http://java.pastebin.com/kvyxruH0
1) As you can see I overdrive some settings getEMF.
2) How should a use EM instances; one for all the app, is that different on
desktop & web ?
3) How could I change HSQLDB options with hibernate to use CACHED tables by
default ?
[1] sqliteJDBC http://www.zentus.com/sqlitejdbc/ + hibernate-sqlite
http://code.google.com/p/hibernate-sqlite/
14 years, 8 months