[jboss-user] [EJB 3.0] - Re: List in EJB3 Entity:

adamcc do-not-reply at jboss.com
Thu Oct 12 07:52:27 EDT 2006


Thank you both very much for taking the time to reply.  :-)

As you correctly said Andy, what I am looking for is to have a persistent attribute with multiple cardinality in my entity.  

I know I could simply define another entity and then use @OneToMany to define an association.  In this case, however, the attribute is very simple (just a List of Strings or an array of longs), and it is only useful in the context of the parent entity - in short there's no real need to define a separate entity.  That's why I thought to reduce the granularity of the entity interface by making it a simple attribute with multiple cardinality.

I am a little surprised that the EJB3 specification doesn't support this requirement, and I had hoped to avoid using vendor specific extensions to the spec.  It seems that's not feasable in this case, so I tried your solution and I'm glad to say it seems to work.  :-)

    @CollectionOfElements
  |     public List<String> getStringList() {
  |     	return _stringList;
  |     }
  |     
  |     public void setStringList(List<String> stringList) {
  |     	_stringList = stringList;
  |     }
  | 
  |     @CollectionOfElements
  |     @IndexColumn(name="longArray_index")
  |     public long[] getLongArray() {
  |     	return _longArray;
  |     }
  | 
  |     public void setLongArray(long[] longArray) {
  |     	_longArray = longArray;
  |     }

Now when I start the server, it deploys the entity and creates a set of 3 tables in the (mysql) database: simpleentity, simpleentity_longarray and simpleentity_stringlist.  The strange thing is that I now get the following series of warnings during startup:


  | 13:22:57,651 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,651 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:57,666 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,666 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:57,713 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,713 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:57,713 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,713 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:57,713 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,713 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:57,713 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,713 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 13:22:57,744 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,744 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:57,744 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,744 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:57,744 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,744 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 13:22:57,869 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,869 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:57,869 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,869 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:57,869 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:57,869 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 13:22:58,009 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,009 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:58,009 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,009 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:58,009 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,009 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 13:22:58,087 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,087 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:58,087 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,087 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:58,087 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,087 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 13:22:58,181 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,181 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity'
  | 13:22:58,181 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,181 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_longarray'
  | 13:22:58,181 WARN  [JDBCExceptionReporter] SQL Warning: 1051, SQLState: 42S02
  | 13:22:58,181 WARN  [JDBCExceptionReporter] Unknown table 'simpleentity_stringlist'
  | 
As I mentioned above, I checked the database and it definitely does have the 3 listed tables in it.

I'll dig deeper in to the hibernate documentation and let you know how I go.

Thanks again very much for your help,

Adam


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977853#3977853

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977853



More information about the jboss-user mailing list