Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reference to element in list  RSS feed

Alex Avb
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please, help with the following problem.
I have object A, that contains a List of String elements (I use List because I need an order of this Strings). In object B I want to have a field, that refers to element in this List on some position (I mean, B has String field, that contains String object from List on some position). Is it posible?

I have the following:

class A {
private List values = new ArrayList(); //contains Strings

* @hibernate.list table="Values" cascade="all"
* @hibernate.collection-key column="A_ID"
* @hibernate.collection-index column="index"
* @hibernate.collection-element column="value" type="java.lang.String"
public List getValues() {
return values;

class B {
private String value;

//What should I put here??
public String getValue() {
return value;

There is composite foreign key, that consist of index and A_ID.. I don't know how to solve it
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!