-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: @Entity no longer able to cast to it's interface
PostPosted: Tue Dec 30, 2014 8:48 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Hi,
I am dusting off some old prototype code that last worked on Hibernate JPA1.0, Glassfish 3.x to Hibernate 4.3.7-Final, Glassfish 4 and JPA2.1. I am seeing an odd problem where an @Entertity class cannot be cast to it's interface (this previously worked for many many months).

Here is a small example:

@Entity
@Table(name = "accounts")
public class UserAccountBean implements Serializable,UserAccount {

/**
*
*/
private static final long serialVersionUID = 6603302682644224769L;

@Id
@SequenceGenerator(name = "usersIdSequence", sequenceName = "users_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "usersIdSequence")
@Column(name = "id", nullable = false)
private Integer id;

... various fields and accessors etc.
}

public interface UserAccount extends Serializable {

Employee getEmployee();

Customer getCustomer();

.. more accessors

}


And the calling code (showing problem):

@Override
public UserAccount authenticateUser(final String username, final String password) {
Query query = em.createQuery("select u from UserAccountBean u where u.username = :username");
query.setParameter("username", username);
List<UserAccount>userList = query.getResultList();

boolean test = userList != null;

test = userList.size() == 1; // this works and shows 1 entry was retrieved - using a debugger I can see it is correct

test = userList.get(0).getPassword().equals(password); // this goes BANG! on the get(0) where it performs a cast returning from the container

}


Warning: A system exception occurred during an invocation on EJB UserAccountServiceBean, method: public <package>.UserAccount <package>.UserAccountServiceBean.authenticateUser(java.lang.String,java.lang.String)
Warning: javax.ejb.EJBException

Caused by: java.lang.ClassCastException: <package>.UserAccountBean cannot be cast to <package>.UserAccount

Any ideas? has something changed in this area? looks pretty simple and standard to me...

</scratching head>


Top
 Profile  
 
 Post subject: Re: @Entity no longer able to cast to it's interface
PostPosted: Tue Dec 30, 2014 9:37 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Update: Something definitely appears to be odd - using the debugger I can evaluate userList.get(0).getPassword() and it shows me the retrieved password....


Top
 Profile  
 
 Post subject: Re: @Entity no longer able to cast to it's interface
PostPosted: Tue Dec 30, 2014 11:12 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Update 2: Tried Hibernate 4.3.5-Final and it all works (same config).

So, 4.3.7-Final seems to be the issue, at least for my setup. I initially followed these instructions https://coderwall.com/p/e5fxrw/use-hibernate-4-3-x-with-jta-on-glassfish-4 to get me going.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.