JPA read-only database

0

Good morning, I have an affair, atypical for me. A database where I need to do select and update in 1 or 2 columns of a table. I would like to know how to configure my persistence.xml

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="nfse" transaction-type="RESOURCE_LOCAL">
        <class>nfse.vo.nfse.vo.CancelamentoNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.CompNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.ConfirmacaoCancelamentoV3Vo</class>
        <class>nfse.vo.nfse.vo.ContatoV3Vo</class>
        <class>nfse.vo.nfse.vo.CpfCnpjV3Vo</class>
        <class>nfse.vo.nfse.vo.DadosConstrucaoCivilV3Vo</class>
        <class>nfse.vo.nfse.vo.DadosPrestadorV3Vo</class>
        <class>nfse.vo.nfse.vo.DadosServicoV3Vo</class>
        <class>nfse.vo.nfse.vo.DadosTomadorV3Vo</class>
        <class>nfse.vo.nfse.vo.EnderecoV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoIntermediarioServicoV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoOrgaoGeradorV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoPrestadorV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoRpsV3Vo</class>
        <class>nfse.vo.nfse.vo.IdentificacaoTomadorV3Vo</class>
        <class>nfse.vo.nfse.vo.InfConfirmacaoCancelamentoV3Vo</class>
        <class>nfse.vo.nfse.vo.InfNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.InfPedidoCancelamentoV3Vo</class>
        <class>nfse.vo.nfse.vo.InfRpsV3Vo</class>
        <class>nfse.vo.nfse.vo.InfSubstituicaoNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.ListaRpsV3Vo</class>
        <class>nfse.vo.nfse.vo.LoteRpsV3Vo</class>
        <class>nfse.vo.nfse.vo.MensagemRetornoLoteV3Vo</class>
        <class>nfse.vo.nfse.vo.MensagemRetornoLoteV3Vo</class>
        <class>nfse.vo.nfse.vo.MensagemRetornoV3Vo</class>
        <class>nfse.vo.nfse.vo.NfseV3Vo</class>
        <class>nfse.vo.nfse.vo.PedidoCancelamentoV3Vo</class>
        <class>nfse.vo.nfse.vo.RpsV3Vo</class>
        <class>nfse.vo.nfse.vo.SubstituicaoNfseV3Vo</class>
        <class>nfse.vo.nfse.vo.ValoresV3Vo</class>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:mysql://192.168.150.3:3306/NFe"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="n9KN2T"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.current_session_context_class" value="thread"/>
            <property name="hibernate.connection.pool_size" value="5"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.format_sql" value="true"/>
        </properties>
    </persistence-unit>
    <persistence-unit name="source" transaction-type="RESOURCE_LOCAL">
        <class>nfse.vo.nfse.vo.NfeDados</class>
        <class>nfse.vo.nfse.vo.NfeClientes</class>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:mysql://192.168.150.2:3306/meubanco"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="nfe"/>
            <property name="hibernate.connection.password" value="r5NvjZR"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.current_session_context_class" value="thread"/>
            <property name="hibernate.connection.pool_size" value="5"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.format_sql" value="true"/>
        </properties>
    </persistence-unit>

</persistence>
    
asked by anonymous 10.01.2018 / 15:10

1 answer

0

In your case you can perform the modification on the entity or the database.

In JAVA add the annotation @Column with the attribute of insertable = false if you want to prevent inserts and updatable = false to not allow updates:

@Column(name="coluna", updatable=false, insertable=false)
private Object coluna;

In the bank , modify a user's permission for tables you can use the following command:

GRANT SELECT, INSERT, UPDATE, DELETE ON nome_do_banco.nome_da_tabela TO 'usuario'@'localhost';

To restrict the user from creating or deleting records modify the command to:

 GRANT SELECT, UPDATE ON nome_do_banco.nome_da_tabela TO 'usuario'@'localhost';

For another situation just change the command according to your need.

    
10.01.2018 / 15:39