Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Hibernate Basics Getting Started with Hibernate Adding JPA Annotations to an Entity

Dan Brown
Dan Brown
12,427 Points

Where am I going wrong?

Course question: Annotate the Language class with JPA annotations so that Language objects can be persisted to the database. Be sure to mark the ID as a generate value, using the IDENTITY strategy. Where am I going wrong?

com/teamtreehouse/coding/model/Language.java
package com.teamtreehouse.coding.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Language {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Column
  private String name;

  @Override
  public Language(Long id, String name) {
    this.id = id;
    this.name = name;
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

2 Answers

Simon Coates
Simon Coates
28,694 Points
//removed code here
  public Language(Long id, String name) {
    this.id = id;
    this.name = name;
  }

I'm no expert, but i'm not sure it makes sense to indicate that the constructor overrides

Dan Brown
Dan Brown
12,427 Points

You were right! Thank you!

package com.teamtreehouse.coding.model;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id;

@Entity public class Language {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;

@Column private String name;

{ }

public Long getId() { return id; }

public void setId(Long id) { this.id = id; }

public String getName() { return name; }

public void setName(String name) { this.name = name; } }