0

i've got a a question i hope you can help me. I want to create a Annotation for my little little database framework but how can i create this with a annotation?

@Columns({name="id", type="long"},{name="username",type="string"})

Simple annotation ca have a String[] butt i want a key/value in this array.

Thanks for you help.

2 Answers 2

2

more annotations of same type aren't allowed,you can change a total realization of ideas

public @interface Column {
      String name();
      String type();
}
public @interface Columns {
    Column[] value();
}

@Columns({@Column(name="id", type="long"), @Column(name="username",type="string")})
public void test() {}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes thats fine. Thanks.
0

Create the annotation class that itself holds a key-value pair. Then, use it as parameter to another annotation that accepts array. Would be something like

 @Columns(columns =
   @Column{name = "name", type = "type"},
   @Column{name = "name", type = "type"}, 
   @Column{name = "name", type = "type"}
 )

See Hibernate @SecondaryTable for inspiration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.