Eu to fazendo um programa que cria personagens de RPG como estudo, mas na hora de inserir eles no banco de dado ta dando esse erro "ORA-00001: restrição exclusiva". Pelo que eu pesquisei esse erro acusa que eu estou tentando dar um insert com uma chave que já existe, mas a chave primária dos objetos que eu tô colocando são diferentes.
Eu fiz o seguinte: Primeiro fiz o insert com os 4 players e deu certo, tão os 4 salvos no banco de dados, mas aí na hora do insert dos characters, só o c4 foi incluso, os outros 3 deram esse erro.
método na classe CharacterDAO:
public void includeChar(Character character) {
conexao = GerenciadorBD.obterConexao();
PreparedStatement comandoSQL = null;
try {
comandoSQL = conexao.prepareStatement("insert into CHARACTER(IDCHAR, CHARNAME, STRENGHT, INTELIGENCE, LUCK,"
+ "CHARISMA, HPPOINTS, ARMOR, PLAYER, CHARRACE, SPEED, CHARLEVEL)values(?,?,?,?,?,?,?,?,?,?,?,?)");
comandoSQL.setInt(1, character.getCharId());
comandoSQL.setString(2, character.getCharName());
comandoSQL.setInt(3, character.getStrenght());
comandoSQL.setInt(4, character.getInteligence());
comandoSQL.setInt(5, character.getLuck());
comandoSQL.setInt(6, character.getCharisma());
comandoSQL.setInt(7, character.getHp());
comandoSQL.setInt(8, character.getArmor());
comandoSQL.setInt(9, character.getPlayer().getPlayerId());
comandoSQL.setString(10, character.getCharRace().toString());
comandoSQL.setInt(11, character.getSpeed());
comandoSQL.setInt(12, character.getLevel());
comandoSQL.executeUpdate();
conexao.close();
comandoSQL.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
Classe de texte para o método insert:
import DAO.CharacterDAO;
import DAO.PlayerDAO;
import enums.RacesEnum;
import model.Character;
import model.Player;
public class testeCharacter {
public static void main(String[] args) {
Player p1 = new Player(01, "Thiago");
Player p2 = new Player(02, "Pedro");
Player p3 = new Player(03, "Julia");
Player p4 = new Player(04, "Mirella");
Character c1 = new Character();
c1.setCharId(01);
c1.setCharName("Talion");
c1.setStrenght(10);
c1.setInteligence(10);
c1.setLuck(0);
c1.setCharisma(0);
c1.setHp(100);
c1.setArmor(10);
c1.setPlayer(p1);
c1.setCharRace(RacesEnum.HUMAN);
c1.setSpeed(10);
c1.setLevel(1);
Character c2 = new Character();
c1.setCharId(02);
c1.setCharName("Legolas");
c1.setStrenght(10);
c1.setInteligence(10);
c1.setLuck(0);
c1.setCharisma(0);
c1.setHp(100);
c1.setArmor(10);
c1.setPlayer(p2);
c1.setCharRace(RacesEnum.ELF);
c1.setSpeed(10);
c1.setLevel(1);
Character c3 = new Character();
c1.setCharId(03);
c1.setCharName("Gimli");
c1.setStrenght(10);
c1.setInteligence(10);
c1.setLuck(0);
c1.setCharisma(0);
c1.setHp(100);
c1.setArmor(10);
c1.setPlayer(p3);
c1.setCharRace(RacesEnum.DWARF);
c1.setSpeed(10);
c1.setLevel(1);
Character c4 = new Character();
c1.setCharId(04);
c1.setCharName("Frodo");
c1.setStrenght(10);
c1.setInteligence(10);
c1.setLuck(0);
c1.setCharisma(0);
c1.setHp(100);
c1.setArmor(10);
c1.setPlayer(p4);
c1.setCharRace(RacesEnum.HALFLING);
c1.setSpeed(10);
c1.setLevel(1);
CharacterDAO cDAO = new CharacterDAO();
PlayerDAO pDAO = new PlayerDAO();
// pDAO.includePlayer(p1);
// pDAO.includePlayer(p2);
// pDAO.includePlayer(p3);
// pDAO.includePlayer(p4);
cDAO.includeChar(c1);
cDAO.includeChar(c2);
cDAO.includeChar(c3);
cDAO.includeChar(c4);
}
}