Announcement Announcement Module
Collapse
No announcement yet.
Can annotations be set on a sub class? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can annotations be set on a sub class?

    I have a business logic bean where I need to abstract the DAO implementation so that either a Hibernate/SQL table can implement the persistence or a Neo4J data store.

    I'd like use annotations for the Neo4J node entity ('User') but this data bean is defined elsewhere and putting Neo4J annotations on the User class isn't an option.

    Here's a code example:
    Code:
    public class User implements Serializable {
    	private static final long serialVersionUID = 1L;
    	private long ID;
    	private String FirstName;
    	private String Surname;
    	private String UserName;
    	public User() {
    	}
    }
    
    public interface UserManager {
       public long add(User aNewUser);
    }
    
    public class UserManagerImpl implements UserManager {
    	private UserDAO DAO;
    	public UserManagerImpl() {
    	}
    
    	@Override
    	public long add(User aNewUser) {
                        return DAO.addUser(aNewUser);
    	}
    
    }
    
    public interface UserDAO {
       public long add(User aNewUser);
    }
    
    public class Neo4JUserDAOImpl implements UserDAO {
    
    	public Neo4JUserDAOImpl() {
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public long add(User aNewUser) {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    }
    I'm wondering if its possible to create a sub class, like:

    Code:
          public class Neo4JUser extends User {
          }
    ... and somehow put the class and field level annotations into 'Neo4JUser'. Can you place field level annotations in a subclass? Then in my Neo4J DAO implementation class I can work with Neo4JUser classes.

    Code:
    public class Neo4JUserDAOImpl implements UserDAO {
    	@Override
    	public long add(User aNewUser) {
                      Neo4JUser aUser = aNewUser.copy();
                      template.save(aUser);
    	}
    
    }
    Thoughts?
Working...
X