Ahojte,
pouzival jsem pro hibernate vzdy xml soubory a vse fungovalo jak jsem
potreboval. Ted se snazim prejit na annotace a mam problem s tim ze mi pri
dotazech pise NullPointerException. Pritom session factory neni null,
criteria taky ne a session taktez ne.
Pouzivam v soucasne dobe hibridni pristup. Tedy mam jednu
hibernateSessionFactory pro annotace, druhou mam pro klasickou konfiguraci
pres xml. Soubor s anotovanym objektem mi normalne najde. Tam zadny
problem neni. Jenom kdyz zjistuju pocet objektu v kolekci.
konfigurace springu:
<!-- hibernate OR mapping -->
<bean id="hibernateSessionFactory4Annotations"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSourceAnnotations" />
<property name="configurationClass"
value="org.hibernate.cfg.AnnotationConfiguration"/>
<property name="configLocation"
value="classpath:mappings/hibernate.annotations.cfg.xml"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.bytecode.provider">javassist</prop>
<prop key="hibernate.show_sql">true</prop>
<prop
key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
v souboru hibernate.annotations.cfg.xml je nasledujici radek:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="net.itsynapse2.ecomerce.entity.bank.BankTransfer"/>
</session-factory>
</hibernate-configuration>
Anotovany objekt:
@Entity
@Table(name="ecomerce_bank_bankTransfers")
public class BankTransfer implements Cloneable, IHibernateCloneable {
protected long transferId = 0; // cislo
bankovniho transferu
protected BankAccount bankAccountIn = new BankAccount(); // cislo
bankovniho uctu odesilatele
protected BankAccount bankAccountOut = new BankAccount(); // cislo
bankovniho uctu prijemce
protected long variableSymbol = 0; //
variabilni symbol
protected long specificSymbol = 0; //
specificky symbol
protected long constantSymbol = 0; //
konstantni symbol
protected double price = 0; // castka
protected int currencyCode = 0; // kod meny
protected String currencyTextCode = ""; // kod
meny jako text
protected Date transferTS = new Date(0); // datum
provedeni transakce
protected long assignedTaxDocumentOid = 0; // cislo
prirazeneho danoveho dokladu
protected int assignedTaxDocumentType = 0; // typ
danoveho dokladu
protected int assignState = 0; // stav
prirazeni transferu k danovemu dokladu
protected String originalText = ""; //
originalni text
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="ecomerce_bank_bankTransfers_transferId_seq")
public void setTransferId( long transferId ) { this.transferId =
transferId; }
public long getTransferId() { return transferId; }
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="bankAccountId", column =
@Column(name="accountIn_bankAccountId") ),
@AttributeOverride(name="accountPrefix", column =
@Column(name="accountIn_accountPrefix") ),
@AttributeOverride(name="accountNumber", column =
@Column(name="accountIn_accountNumber") ),
@AttributeOverride(name="iban", column =
@Column(name="accountIn_iban") ),
@AttributeOverride(name="bankCode", column =
@Column(name="accountIn_bankCode") ),
@AttributeOverride(name="name", column =
@Column(name="accountIn_bankTextCode") )
} )
public void setBankAccountIn( BankAccount bankAccountIn ) {
this.bankAccountIn = bankAccountIn; }
public BankAccount getBankAccountIn() { return bankAccountIn; }
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="bankAccountId", column =
@Column(name="accountOut_bankAccountId") ),
@AttributeOverride(name="accountPrefix", column =
@Column(name="accountOut_accountPrefix") ),
@AttributeOverride(name="accountNumber", column =
@Column(name="accountOut_accountNumber") ),
@AttributeOverride(name="iban", column =
@Column(name="accountOut_iban") ),
@AttributeOverride(name="bankCode", column =
@Column(name="accountOut_bankCode") ),
@AttributeOverride(name="name", column =
@Column(name="accountOut_bankTextCode") )
} )
public void setBankAccountOut( BankAccount bankAccountOut ) {
this.bankAccountOut = bankAccountOut; }
public BankAccount getBankAccountOut() { return bankAccountOut; }
@Column(name="variableSymbol")
public long getVariableSymbol() { return variableSymbol; }
public void setVariableSymbol( long variableSymbol ) {
this.variableSymbol = variableSymbol; }
@Column(name="specificSymbol")
public long getSpecificSymbol() { return specificSymbol; }
public void setSpecificSymbol( long specificSymbol ) {
this.specificSymbol = specificSymbol; }
@Column(name="constantSymbol")
public long getConstantSymbol() { return constantSymbol; }
public void setConstantSymbol( long constantSymbol ) {
this.constantSymbol = constantSymbol; }
@Column(name="price")
public double getPrice() { return price; }
public void setPrice( double price ) { this.price = price; }
@Column(name="currencyCode")
public int getCurrencyCode() { return currencyCode; }
public void setCurrencyCode( int currencyCode ) { this.currencyCode =
currencyCode; }
@Column(name="currencyTextCode")
public String getCurrencyTextCode() { return currencyTextCode; }
public void setCurrencyTextCode( String currencyTextCode ) {
this.currencyTextCode = currencyTextCode; }
@Column(name="transferTS")
public Date getTransferTS() { return transferTS; }
public void setTransferTS( Date transferTS ) { this.transferTS =
transferTS; }
@Column(name="assignedTaxDocumentOid")
public long getAssignedTaxDocumentOid() { return
assignedTaxDocumentOid; }
public void setAssignedTaxDocumentOid( long assignedTaxDocumentOid ) {
this.assignedTaxDocumentOid = assignedTaxDocumentOid; }
@Column(name="assignedTaxDocumentType")
public int getAssignedTaxDocumentType() { return
assignedTaxDocumentType; }
public void setAssignedTaxDocumentType( int assignedTaxDocumentType )
{ this.assignedTaxDocumentType = assignedTaxDocumentType; }
@Column(name="assignState")
public int getAssignState() { return assignState; }
public void setAssignState( int assignState ) { this.assignState =
assignState; }
@Column(name="originalText")
public String getOriginalText() { return originalText; }
public void setOriginalText( String originalText ) { this.originalText
= originalText; }
}
Chyba kterou mi to hlasi pri inicializaci do logu - ten posledni radek.
Pritom ty anotace projde.:
2007-11-21 12:25:29,887 INFO [org.hibernate.cfg.annotations.Version] -
<Hibernate Annotations 3.3.0.GA>
2007-11-21 12:25:29,957 INFO [org.hibernate.cfg.Environment] - <Hibernate
3.2.3>
2007-11-21 12:25:29,977 INFO [org.hibernate.cfg.Environment] -
<hibernate.properties not found>
2007-11-21 12:25:29,983 INFO [org.hibernate.cfg.Environment] - <Bytecode
provider name : cglib>
2007-11-21 12:25:29,998 INFO [org.hibernate.cfg.Environment] - <using JDK
1.4 java.sql.Timestamp handling>
2007-11-21 12:25:30,535 INFO [org.hibernate.cfg.Configuration] -
<configuring from url:
file:/home/pet/work/svn/itsynapse20/trunk/target/itsynapse20-2.0-SNAPSHOT/WEB-INF/classes/mappings/hibernate.annotations.cfg.xml>
2007-11-21 12:25:30,621 INFO [org.hibernate.cfg.Configuration] -
<Configured SessionFactory: null>
Kdyz napisu do toho souboru hibernate.annotations.cfg.xml nazev annotovane
tridy spatne, tak mi to vyhlasi ze neexistuje. Takze zjevne tu tridu
najde. Akorat je divne ze pak nenapise jako pri klasicke inicializaci
pomoci xml neco ve stylu:
2007-11-21 12:46:59,221 INFO [org.hibernate.cfg.HbmBinder] - <Mapping
class: net.itsynapse2.ecomerce.entity.article.Article -> ecomerce_article>
Problem je pak kdyz chci nejake radky pomoci criteria dostat tak mi to
vyhlasi NullPointerException. Za jakoukoliv radu budu moc rad.
Pet
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/