我正在尝试使用配置文件ID更新我的配置文件模块..但它没有更新..我收到以下错误: [PersistenceException:ERROR执行DML bindLog []错误[错误:多次分配到同一列“register_id”]]
我附加了我的控制器类..在编辑方法中我尝试了更新查询
控制器类:
package controllers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import models.*;
import org.apache.commons.mail.EmailException;
import play.Logger;
import play.data.Form;
import play.libs.F.Promise;
import play.libs.OpenID;
import play.libs.OpenID.UserInfo;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.*;
import com.avaje.ebean.Ebean;
import com.typesafe.plugin.MailerAPI;
import com.typesafe.plugin.MailerPlugin;
public class Application extends Controller {
public static Result index() {
return ok(index.render(""));
}
public static Result signup() {
return ok(login.render(null));
}
public static Result register() {
Register register = Form.form(Register.class).bindFromRequest().get();
register.save();
return ok(index.render(""));
}
public static Result login() {
Register register = Form.form(Register.class).bindFromRequest().get();
String uname = register.getUsername();
String pass = register.getPassword();
List<Register> login = Register.find.where().eq("username", uname)
.eq("password", pass).findList();
if (login.isEmpty()) {
return unauthorized("Please register and try login");
} else {
session().clear();
session("registerId", +login.get(0).getRegisterId() + "");
return ok(app.render("register"));
}
}
public static Result home() {
return ok(app.render(""));
}
public static Result menu() {
Register register = Form.form(Register.class).bindFromRequest().get();
String uname = register.getUsername();
String pass = register.getPassword();
List<Register> login = Register.find.where().eq("username", uname)
.eq("password", pass).findList();
session("registerId", +login.get(0).getRegisterId() + "");
String reg=session().get("registerId");
System.out.println(reg);
Profile profile1=Profile.find.byId(reg);
System.out.println(profile1);
if(profile1!=null)
{
return ok(profile.render(profile1));
}
else
return ok(empty.render(""));
}
public static Result edit(int profileId) {
Form<Profile> profile1 = Form.form(Profile.class).bindFromRequest();
profile1.get().update(profileId);
return ok("");
}
public static Result logout() {
return ok(index.render("fhjk"));
}
public static Result profile() {
Profile profile = Form.form(Profile.class).bindFromRequest().get();
profile.getRegister().setRegisterId(
Integer.parseInt(session().get("registerId")));
profile.save();
return ok();
}
public static Result forgotPassword() {
return ok(forgotPassword.render("eghj"));
}
public static Result email() throws EmailException {
ForgotPassword forgotPass = Form.form(ForgotPassword.class)
.bindFromRequest().get();
String emailId = forgotPass.getEmail();
System.out.println(emailId);
MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
mail.setSubject("mailer");
mail.setRecipient(emailId);
mail.setFrom("sindhu.raja90@gmail.com");
mail.send( "text" );
return ok("gg");
}
@SuppressWarnings("serial")
public static final Map<String, String> identifiers = new HashMap<String, String>() {
{
put("google", "https://www.google.com/accounts/o8/id");
}
};
@SuppressWarnings("deprecation")
public static Result auth() {
Logger.debug("authenticate");
String providerId = "google";
String providerUrl = identifiers.get(providerId);
String returnToUrl = "http://localhost:9000/login/verify";
if (providerUrl == null) {
return badRequest("Could not find provider " + providerId);
}
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("Email", "http://schema.openid.net/contact/email");
attributes
.put("FirstName", "http://schema.openid.net/namePerson/first");
attributes.put("LastName", "http://schema.openid.net/namePerson/last");
Promise<String> redirectUrl = OpenID.redirectURL(providerUrl,
returnToUrl, attributes);
return redirect(redirectUrl.get());
}
@SuppressWarnings("deprecation")
public static Result verify() {
Logger.debug("verifyLogin");
System.out.println("verify executed");
Promise<UserInfo> userInfoPromise = OpenID.verifiedId();
userInfoPromise.get();
return ok("");
}
}
Profile.views.html:
@(profile1: Profile)
@main("") {
<div class="container test">
<!-- form: -->
<section>
<div class="col-lg-8 col-lg-offset-2">
<label> <a href="@routes.Application.home()">Home</a>
</label>
<label> <a href="@routes.Application.logout" class="logout">Logout</a>
</label>
<div class="page-header">
<h2>Profile</h2>
</div>
<form class="form-horizontal" method="POST" id="profile"
action="@routes.Application.profile()">
<div class="input-group">
<input type="file" class="file">
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="firstName">First
Name:</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="firstname" value='@profile1.getFirstname'
id="firstName" autocomplete="off" required
data-bv-notempty-message="The first name is required" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="middleName">Middle
Name:</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="middlename" value='@profile1.getMiddlename'
autocomplete="off" id="middleName">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="lastName">Last
Name:</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="lastname" value="@profile1.getLastname"
id="lastName" autocomplete="off" required
data-bv-notempty-message="The last name is required" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Date of Birth:</label>
<div class="col-xs-4">
<input type="date" class="form-control" name="dob" id="dob" value="@profile1.getDob"
autocomplete="off" data-bv-date="false"
data-bv-date-message="The birthday is not valid" required
data-bv-notempty-message="The date of birth is required" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Gender:</label>
<div class="col-xs-2">
<label class="radio-inline"> <input type="radio"
name="gender" value="male" required
data-bv-notempty-message="The gender is required" /> Male
</label>
</div>
<div class="col-xs-2">
<label class="radio-inline"> <input type="radio"
name="gender" value="female"> Female
</label>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="maritalStatus">Marital
Status: </label>
<div class="col-lg-4">
<select class="form-control" name="maritalStatus">
<option value="single">Single</option>
<option value="married">Married</option>
<option value="divorced">Divorced</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="permanentAddress">Permanent
Address:</label>
<div class="col-lg-4">
<textarea rows="3" class="form-control" name="permanentAddress"
id="permanentAddress" required
data-bv-notempty-message="The permanent address is required">@profile1.getPermanentAddress</textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="tempAddress">Temporary
Address:</label>
<div class="col-lg-4">
<textarea rows="3" class="form-control" name="tempAddress"
id="tempAddress" required
data-bv-notempty-message="The temporary address is required">@profile1.getTempAddress</textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="bloodGroup">Blood
Group:</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="bloodGroup"
id="bloodGroup" value="@profile1.getBloodGroup" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="idMark">Identification
Mark:</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="identificationMark" value="@profile1.getIdentificationMark"
id="idMark" autocomplete="off" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="personalNo">Personal
No:</label>
<div class="col-lg-4">
<input type="tel" class="form-control" name="personalNum" value="@profile1.getPersonalNum"
id="personalNo" autocomplete="off" required
data-bv-notempty-message="The phone no is required">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="emergencyNo">Emergency
No:</label>
<div class="col-lg-4">
<input type="tel" class="form-control" name="emergencyNum" value="@profile1.getEmergencyNum"
id="emergencyNo" autocomplete="off" required
data-bv-notempty-message="The phone no is required">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="location">Location:
</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="location" value="@profile1.getLocation"
id="location" autocomplete="off">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="state">State: </label>
<div class="col-lg-4">
<input type="text" class="form-control" name="state" value="@profile1.getState" id="state">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label" for="country">Country:
</label>
<div class="col-lg-4">
<input class="form-control" name="country" value="@profile1.getCountry" id="country"
type="text">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-3 col-xs-9">
<input type="submit" class="btn btn-primary" id="submit" value="Submit" >
</div>
</div>
</form>
<div>
<form method="get" action="@routes.Application.edit(profile1.getProfileId)">
<input type="submit" class="btn btn-primary" id="edit" value="edit" onclick="disableTxt()"/>
</form>
</div>
</div>
</section>
</div>
<script type="text/javascript">
function disableTxt() {
document.getElementById('country').disabled='true';
}
</script>
<style type="text/css">
.form-horizontal .control-label {
text-align: left;
}
.test .input-group .btn-default,.form-control.file-caption,.glyphicon,.close
{
display: none;
}
.sample {
margin-bottom: 50px;
}
.test .btn-file:hover {
background: #ffffff;
border: none;
}
</style>
}
模特课:
package models;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import play.db.ebean.Model;
@Entity
@Table(name = "profile")
public class Profile extends Model {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator ="profile_profile_id_seq")
private int profileId;
public int getProfileId() {
return profileId;
}
public void setProfileId(int profileId) {
this.profileId = profileId;
}
@OneToOne
@JoinColumn(table="register", name= "register_id")
private Register register;
private int registerId;
public Register getRegister() {
return register;
}
public void setRegister(Register register) {
this.register = register;
}
public Profile(){
register = new Register();
}
private byte[] photo;
@Column(name="firstname")
private String firstname;
private String middlename;
private String lastname;
private Date dob;
private String gender;
private String maritalStatus;
private String permanentAddress;
private String tempAddress;
private String bloodGroup;
private String identificationMark;
private String personalNum;
private String emergencyNum;
private String location;
private String state;
private String country;
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
public String getIdentificationMark() {
return identificationMark;
}
public void setIdentificationMark(String identificationMark) {
this.identificationMark = identificationMark;
}
public String getPersonalNum() {
return personalNum;
}
public void setPersonalNum(String personalNum) {
this.personalNum = personalNum;
}
public String getEmergencyNum() {
return emergencyNum;
}
public void setEmergencyNum(String emergencyNum) {
this.emergencyNum = emergencyNum;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getMiddlename() {
return middlename;
}
public void setMiddlename(String middlename) {
this.middlename = middlename;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(String maritalStatus) {
this.maritalStatus = maritalStatus;
}
public String getPermanentAddress() {
return permanentAddress;
}
public void setPermanentAddress(String permanentAddress) {
this.permanentAddress = permanentAddress;
}
public String getTempAddress() {
return tempAddress;
}
public void setTempAddress(String tempAddress) {
this.tempAddress = tempAddress;
}
public String getBloodGroup() {
return bloodGroup;
}
public void setBloodGroup(String bloodGroup) {
this.bloodGroup = bloodGroup;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Profile[Photo=");
stringBuilder.append(photo);
stringBuilder.append(",ProfileId=");
stringBuilder.append(profileId);
stringBuilder.append(",FirstName=");
stringBuilder.append(firstname);
stringBuilder.append(",MiddleName=");
stringBuilder.append(middlename);
stringBuilder.append(",LastName=");
stringBuilder.append(lastname);
stringBuilder.append(",Dob=");
stringBuilder.append(dob);
stringBuilder.append(",Gender=");
stringBuilder.append(gender);
stringBuilder.append(",MaritalStatus=");
stringBuilder.append(maritalStatus);
stringBuilder.append(",PermanentAddress=");
stringBuilder.append(permanentAddress);
stringBuilder.append(",TempAddress=");
stringBuilder.append(tempAddress);
stringBuilder.append(",BloodGroup=");
stringBuilder.append(bloodGroup);
stringBuilder.append(",IdentificationMark=");
stringBuilder.append(identificationMark);
stringBuilder.append(",PersonalNum=");
stringBuilder.append(personalNum);
stringBuilder.append(",EmergencyNum=");
stringBuilder.append(emergencyNum);
stringBuilder.append(",Location=");
stringBuilder.append(location);
stringBuilder.append(",Country=");
stringBuilder.append(country);
stringBuilder.append(",State=");
stringBuilder.append(state);
stringBuilder.append(",Register Id=");
stringBuilder.append(register != null ? register.getRegisterId() : "");
stringBuilder.append("]");
return stringBuilder.toString();
}
public int getRegisterId() {
return registerId;
}
public void setRegisterId(int registerId) {
this.registerId = registerId;
}
public static Finder<String, Profile> find = new Finder<String, Profile>(
String.class, Profile.class);
}
答案 0 :(得分:0)
我相信这是因为你有一个“寄存器”被识别为名为“register_id”的列,你还有一个“registerId”的公共getter / setter,它将尝试使用相同的“register_id”列。我建议将registerId重命名为其他名称,例如“testRegisterId”(并将public getter / setter更改为getTestRegisterId和setTestRegisterId)。