Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to set up new details for a current user
    primarykey
    data
    text
    <p>I'm very new to programming and my knowledge of java is limited. I'm tinkering with a template for a facebook like website so i can learn and add features. I'm trying to allow the current user to change their details, such as name, email, password etc., but cant figure out the java to do so. When i try, all that happens is a brand new user is created on top of the current one :/ Here's what I have so far:</p> <pre><code>public static void changeDetails(String firstName, String lastName, String email, String password, String age, String nationality) { Logger.info("New details are: " + firstName + " " + lastName + " " + email + " " + password + " " + age + " " + nationality + " "); User user = new User(firstName, lastName, email, password, age, nationality); user.save(); Home.index(); } </code></pre> <p>and here is the user class:</p> <pre><code>package models; import java.util.List; import java.util.ArrayList; import javax.persistence.OneToMany; import javax.persistence.Entity; import controllers.Home; import play.db.jpa.Model; import play.db.jpa.Blob; @Entity public class User extends Model { public String firstName; public String lastName; public String email; public String password; public String age; public String nationality; public String statusText; public Blob profilePicture; @OneToMany(mappedBy = "sourceUser") public List&lt;Friendship&gt; friendships = new ArrayList&lt;Friendship&gt;(); public User(String firstName, String lastName, String email, String password, String age, String nationality) { this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; this.age = age; this.nationality = nationality; } public static User findByEmail(String email) { return find("email", email).first(); } public boolean checkPassword(String password) { return this.password.equals(password); } public void befriend(User friend) { Friendship friendship = new Friendship(this, friend); friendships.add(friendship); friendship.save(); save(); } public void unfriend(User friend) { Friendship thisFriendship = null; for (Friendship friendship:friendships) { if (friendship.targetUser== friend) { thisFriendship = friendship; } } friendships.remove(thisFriendship); thisFriendship.delete(); save(); } @OneToMany(mappedBy = "to") public List&lt;Message&gt; inbox = new ArrayList&lt;Message&gt;(); @OneToMany(mappedBy = "from") public List&lt;Message&gt; outbox = new ArrayList&lt;Message&gt;(); public void sendMessage (User to, String messageText) { Message message = new Message (this, to, messageText); outbox.add(message); to.inbox.add(message); message.save(); } } </code></pre> <p>I can see my problem is probably "new User and user.save" but I cant figure out what I should have in. thanks for your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload