I have a customer registration and I want to associate this customer with an equipment relationship but it is not saving the relationship.
In the model layer of the client class I did so
@OneToMany(cascade = {CascadeType.ALL } )
@JoinColumn(name = "CLIENTE_ID")
private Collection<Equipamento> equipamentos;
In my front end JS I have this
app.controller("clienteController", function($scope, $http, $filter){
$scope.clientes = [];
$scope.cliente={};
$scope.equipamento={};
$scope.salvarClientes=function(){
if($scope.frmCliente.$valid){
$http({
method : 'POST',
url : 'http://localhost:8080/user/clientes', data:$scope.cliente
}).then(function(response) {
Lobibox.notify('success',
{
title: false,
msg: 'Registro salvo com sucesso!',
delay: 4000,
position: "top right"
}
);
carregarClientes();
$scope.cliente={};
$scope.equipamento={};
}, function(response) {
console.log(response.data);
console.log(response.status);
});
}else{
Lobibox.alert("error",
{
title: "Atenção",
msg: "Campos com * são de preenchimento obrigatório!"
});
}
};
......
In my HTML
<div ng-controller="clienteController">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">Cadastro de Cliente</div>
<div class="panel-body">
<form novalidate name="frmCliente" id="formCadastro" role="form">
<div class="row">
<div class="form-group col-md-12">
<label>* Empresa:</label> <input name="inpEmpresa"
maxlength="60" required="required" type="text"
class="form-control" ng-model="cliente.empresa" />
</div>
<div class="form-group col-md-12">
<label>* CNPJ:</label> <input name="inpCnpj" maxlength="16"
required="required" type="text" class="form-control"
ng-model="cliente.cnpj" />
</div>
<div class="form-group col-md-6">
<label>* Cidade:</label> <input name="inpCidade" maxlength="60"
required="required" type="text" class="form-control"
ng-model="cliente.cidade" />
</div>
<div class="form-group col-md-12">
<label>* Endereço:</label> <input name="inpEndereco"
maxlength="60" required="required" type="text"
class="form-control" ng-model="cliente.endereco" />
</div>
<div class="form-group col-md-12">
<label>* E-mail:</label> <input name="inpEmail" maxlength="50"
required="required" type="email" class="form-control"
ng-model="cliente.email" />
</div>
<div class="form-group col-md-6">
<label>* Telefone:</label> <input name="inpTelefone"
maxlength="15" required="required" type="text"
class="form-control" ng-model="cliente.telefone" />
</div>
<div class="form-group col-md-6">
<label>* Contato:</label> <input name="inpContato"
maxlength="30" required="required" type="text"
class="form-control" ng-model="cliente.contato" />
</div>
<div class="form-group col-md-12">
<label>Observação:</label>
<textarea name="inpObservacao" class="form-control" rows="3"
ng-model="cliente.observacao"></textarea>
</div>
<div></div>
</div>
</form>
<div class="pull-right">
<button type="button" id="btnSalvar" class="btn btn-default"
ng-click="salvarClientes()">Salvar</button>
<!-- ou ng-disabled="frmCliente.inpNome.$invalid" -->
<button type="button" class="btn btn-default"
ng-click="cancelarAlteracaoClientes(cli)">Cancelar
Edição</button>
<button type="button" id="btnAdCadEquipamento"
class="btn btn-default" ng-click="addEquipamento()">
<span class="glyphicon glyphicon-plus"></span>
</button>
</div>
</div>
</div>
</div>
<div ng-controller="equipamentoController">
<div id="cadEquipInsp" class="col-md-6 ">
<div class="panel panel-primary">
<div class="panel-heading">Cadastro de
Equipamentos/Instrumentos</div>
<div class="panel-body">
<form novalidate name="frmEquipamento" id="formCadastro" role="form">
<div class="row">
<div class="form-group col-md-12">
<label>Descrição:</label> <input name="inpDescricao"
maxlength="60" required="required" type="text"
class="form-control" ng-model="equipamento.descricao" />
</div>
<div class="form-group col-md-6">
<label>Data da Inspeção:</label> <input
name="inpDataEquipamento" maxlength="16" required="required"
type="date" class="form-control" ng-model="equipamento.dataEquipamento" />
</div>
<div class="form-group col-md-6">
<label>Próxima Inspeção:</label> <input
name="inpProximaInspecao" maxlength="60" required="required"
type="date" class="form-control" ng-model="equipamento.proximaInspecao" />
</div>
<!-- <div class="pull-right">
<button type="button" id="btnSalvar" class="btn btn-default"
ng-click="salvarEquipamentos()">Salvar</button>
</div> -->
</div>
</form>
</div>
</div>
</div>
</div>