Emmanuel Garcia

Greenhorn
+ Follow
since Feb 24, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Emmanuel Garcia

I need your help.

This the topic:

I am using JPA with Oracle 9i, JBoss 5.x GA and the default provider is Hibernate.

I am working with "Native Query" and my second test for this was a native query with fields of two entities

This is my query

String sql = "SELECT c.firstName as FIRSTNAME, c.lastname as LASTNAME " +
"FROM CUSTOMER c, CREDITCARD cc " +
"WHERE c.creditcard_id = cc.id";


the two columns selected are from customer table, I had more columns, but I have tested this query because I thought that it will be simplier,

the table CUSTOMER has firstname and lastname columns, and more.
the table CREDITCARD has its columns in form.

When I execute the query as:

Query query = manager.createNativeQuery(sql);

List phones = query.getResultList();
System.out.println("size " + phones.size());


I can see: size 5, the 5 rows in the DB.

And I have not problem if I only get the values as such.

If I make this:

Query query = manager.createNativeQuery(sql,"customerAndCreditCardMapping");

List phones = query.getResultList();
System.out.println("size " + phones.size());


With "customerAndCreditCardMapping" into Customer entity as:

@SqlResultSetMapping(name="customerAndCreditCardMapping",
entities={@EntityResult(entityClass=Customer.class,
fields={@FieldResult(name="firstName", column="FIRSTNAME"),
@FieldResult(name="lastName", column="LASTNAME")}
)})



I get the next exception:


org.hibernate.exception.GenericJDBCException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
at com.titan.clients.NativeQueries.nativeWithMultipleEntities(NativeQueries.java:75)
at com.titan.clients.NativeQueries.main(NativeQueries.java:28)
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
... 2 more
Caused by: java.sql.SQLException: Nombre de columna no válido
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:5278)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:698)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1563)
at org.hibernate.type.LongType.get(LongType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 9 more
Exception in thread "main" javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:51)
at com.titan.clients.NativeQueries.main(NativeQueries.java:37)


I ran the SQL from TOAD and it is fine.

The exception is thrown when I try of make the mapping with @SqlResultSetMapping customerAndCreditCardMapping but I don't have idea.

Regards


Thanks Mike and thanks Jeanne Boyarsky for you comment.




I a newby with EJB3.0 but I have worked wiith Hibernate and its persistence API and I know Spring and I can see that Spring uses
persistence with Hibernate, Ibatiz or JPA.

My questions are, if you want to work with JPA ,Is it tied with EJB 3.0? Can I work with JPA without work with EJBs ?

I believe thath JPA is a API as such JDBC, only interfaces, the implementation can be with Hibernate or openJPA, Is it correct ?

Regards.
Hi Laura:

I have a doubt.

What was the first problem ?

because you have spoken about multiplicity, cascade delete, relationships.

Regards.
Hi Laura:

I believe the your boss is correct, but before two things:

1- A relationship OneToMany is the same thing that ManyToOne.
2- A relationship is bidirectional or not if you put in the code the correct method to return anohter bean and the <crm-field> in the descriptor,
in the relationship role in the descriptor you should write the source and destiny beans,
always

What is my opinion ? put <cascade-delete /> in the bean with multiplicity One
Ravi Kiran V

When you use explicitly a EJBException (RuntimeException and "System Exception" in the EJB world) is only for a callback methods and sometimes when you are in a bussiness method and the checked exception is internal and no bussiness.

And raise it is because you realize is a bad idea coontinue with the normal flow therefore is best idea is throws a EJBException
because the Container will do:

1- discard the instance bean
2- log the problem
3. roll back the transaction

But generally when you are in bussiness method and you have a checked exception you should do a call to setRollBackOnly()
and rethrow the checked exception if it is not in the interface method or continue with the bussiness method and check if the transaction
is alive with getRollBackOnly(), maybe it is the main reason to use a EJBException, avoid make extre job.

One more thing, with setRollbackOnly() call you tell to container, the transaction will not commit; remember all this is for CMT.

The exceptions for EJBs is interesting but complicated because there are things for the provider bean and things for the container.


Regards
Hi everybody


Yesterday, I made the second test, I can say you that the test 834 is easier than 833 and I believe that is more interesting too, although the first test is the base to begin with the OOAD.

I passed the test with 96%, I made the test as yet because I didn't have time and money, the cost for this is the same 200 dollars.

You should not forget check the next URL http://certified-es.blogspot.com/ , here there are many questions about these tests, although the title is "Certified (En español)" many questions are in english.

I hope that you share your experience with us, and your mocks, emulators, pages, blogs and so on, about this certification.

Regards
vaka, please read the rules to choose the nickname, and If you want the PDF, send me a private message, It is the unique form.

but first, change the nickname, I have not any problems with the administrator.

I have only one advice, you shoud read the PDF DEV475

Sultan Ahmed wrote:Could someone please reply with which version of Craig Larman's book is needed for exams 833 and 844. I believe the latest version is 3rd edition. I have the 2nd edition and was wondering if I will need the 3rd edition.



Hi. I have the second edition and it is about UML, Patterns and RUP, I read this book and it is great for the test 833/834, but I have to say you that
I read the DEV475 Course from IBM too, I have a copy of this document and the questions are very similar with the information contained in it

The past week I made the test 833 and passed with 100%, but I have reading that the test 834 is more difficult than the 833

If you want the PDF send me a message.

Regards

Pratap Shinde wrote:Use com.ibm.wsspi.extension.ExtensionRegistryFactory class from the jar IBM\SDP70\runtimes\base_v61\bin\ProfileManagement\plugins\com.ibm.websphere.v61_6.1.1\ws_runtime.jar and it will work fine.



Thank you very much It worked fine

Regards
15 years ago
tomcat has something called hot swap, this means that there are daemond checking the changes in your app, all time.
16 years ago
JSP