Posts by Dherik • 10,372 points
299 posts
-
2
votes1
answer115
views -
1
votes1
answer163
views -
3
votes1
answer750
viewsA: JPA make a Join of a table that has attribute @manyToOne and @Manytomany
You did not post the Customer entity code, so I assumed the customer name is in the field nome. See how JPQL looks in this case: SELECT p.nome, c.nome, p.preco, v.dtCompra FROM Venda v JOIN…
-
4
votes3
answers47
viewsA: How to view a given value in a table
With this SQL: SELECT nome FROM pessoas WHERE regiao = 'RS' Explanation: you are selecting (SELECT) the name (nome) of people (table pessoas) in which (WHERE) the region (regiao) is equal (=) a RS.…
-
6
votes2
answers878
viewsA: How to get the number of columns of a temporary table
Try using the following SQL: SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = 'database' AND TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'sua_tabela' For temporary tables,…
-
1
votes1
answer73
viewsA: Java Error - Scheduled
Hello, Error refers to annotation @Component, not imported into your class TestT. To fix, use: import org.springframework.stereotype.Component; I think you’ll have the same problem with…
-
0
votes1
answer313
viewsA: Map relationship between tables without Foreign key
In theory it’s possible, I confess I never tried, but I see no reason why Hibernate couldn’t do the mapping without FK. How you need to map the Declaracao in the Imovel, you need to use some key…
-
2
votes1
answer2602
viewsA: get login username with Spring Security
The way easier to access the logged in user information is by SecurityContextHolder: Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String nome; if…
-
5
votes1
answer1245
viewsA: How to handle Null records? In the database or app? (java & Mysql)
Hello, About your doubts: I treat it in the bank, generating empty values for these records It wouldn’t do that unless it makes sense in the business context of the application. Eventually it will…
-
0
votes2
answers517
viewsA: Understanding the use of Generics in an abstract DAO Hibernate class
Hello, This class is this way so that new Daos can pass different entities to extend this class and thus reuse the methods of this abstract class. For example, if you have an entity Pedido (T), in…
-
3
votes2
answers1920
viewsA: How to modify commits that were not pushed
Yes! You can undo your last commit local (without having pushed), going back to the previous commit state and missing the changes made to it. Just do: git reset --soft HEAD~1 Being 1 the number of…
-
1
votes1
answer97
viewsA: Help with Mongodb
It seems that is an expected behavior. According to the mongodb documentation (griffin mine): For case sensitive regular Expression queries, if an index exists for the field, then Mongodb Matches…
-
1
votes1
answer39
viewsA: How best to relate this entity
It seems to me that the best case is to have a relationship of many to many between User and Class. I understand that this relationship is independent of the Course. This way, you would have: class…
-
2
votes1
answer113
viewsA: Add value at the beginning and end of a mysql string
You can use the function CONCAT. To concatenate the information before of the current value, you can use: UPDATE question_answer SET answer = CONCAT('<p style="display:inline;">', answer ); To…
-
2
votes2
answers1525
viewsA: Restful DELETE method
The idea itself is valid. I haven’t seen any problems since id and codUsuario form some kind of composite key to access this resource in which you want to remove OR both form a URL in which the set…
-
2
votes2
answers118
viewsA: Receive 3 random values and allocate in 3 variables from smallest to largest
You need to start local variables A, B and C with some value. Probably, in your case, with zero: int A = 0, B = 0, C = 0; If the variable is local and the = 0 is omitted, so the variable has no…
-
1
votes2
answers209
viewsA: Creation of a module
You seem to be confused regarding the use of direct import in the interpreter vs the execution of a file .py with Miles inside it. Without the code it is difficult to understand where you are going…
-
11
votes1
answer152
viewsA: Is there any difference in performance between writing a file as a response and writing to a file as a part (buffer)?
There are differences yes. In the first case the file will be loaded entirely into the server memory before it is sent to the client. In the second case the file will be partially loaded in memory…
-
0
votes1
answer212
viewsA: Datasource configuration
I think the problem is here: <max-pool-size>100</max-pool-size> If the database is configured to accept up to 5 connections and you define that it can have up to 100 open connections in…
-
0
votes3
answers1162
viewsA: create objects dynamically
The problem seems to me very simple to have a Factory. I’m having a problem in college in software engineering which is next: I have the following scheme when making the payment of a shopping cart…
-
0
votes2
answers7879
viewsA: Select Join with JPQL
Given the entities, this would be the JPQL query: select usuario from Usuario usuario JOIN usuario.pessoa pessoa WHERE usuario.senha = :senha AND pessoa.matricula = :matricula As a hint, always…
-
2
votes1
answer253
viewsQ: When should a utility class become an injectable dependency?
I often write small utility classes to solve some minor problem in my code. For example (I will use Spring for DI): @Service class PessoaService { public PessoaResponse converter(Pessoa pessoa, Long…
-
1
votes1
answer300
viewsA: Conversion of float to string - how to display two or more decimal places?
You can use this method: public BigDecimal toBigDecimal(float number) { BigDecimal bd = new BigDecimal(Float.toString(number)); // converte para BigDecimal bd.setScale(2, BigDecimal.ROUND_HALF_UP);…
-
1
votes2
answers113
viewsA: How to make a query per ID in HQL using the LIKE operator?
Without the entity code you can’t be sure, but you can try something like this: String hql = "select c from entidadeQualquer c where CAST(id as text) like :id"; And to set the parameter: Query query…
-
26
votes3
answers2737
viewsA: How to integrate microservices?
I think leaving for a distributed transaction is the last case using micro services. I understand that certain activities of a solution are isolated and can be an easy microservice. But others seem…
-
2
votes2
answers358
viewsA: Good Practice for Rest Services
Well, as I understand it, you’re talking about omitting a null attribute. For example, instead of returning: { atributo1: "Hello", atributo2: null, } Your colleague recommends: { atributo1: "Hello"…
-
3
votes2
answers2071
viewsA: When to use static methods mock?
I’m going to assume that we’re not going to get into the merits of refactoring a code with static methods, because I think this would be another discussion. Let’s have your questions. If we can do…
-
1
votes2
answers74
views -
1
votes2
answers287
viewsA: How to avoid Lazyexceptions?
When we perform a very large flow in the system, it is more likely that a Lazy will occur? I get the list of values one line above when I try to access the items and already got the Exception. Yes,…
-
0
votes1
answer39
viewsA: Get the content size returned in the request
You can read the content-length Response Header to get this information: response.getHeader("content-length"); This information corresponds to the size of the compressed Response (if applicable) by…
-
0
votes2
answers198
viewsA: Commit Reversal
From what I understand, I believe you want this in your development branch: --> C0 ---> C1 --> C1' C0 is the commit before yours C1 is when you committed the change and showed it to the…
-
1
votes0
answers320
viewsQ: CPF Hibernate Constraint does not accept valid CPF?
I’m trying to run the Hibernate CPF validation Constraint, but it just seems to reject valid CPF. The same test using Email Straint works normally: EmailValidator validator = new EmailValidator();…
-
0
votes5
answers2766
viewsA: What HTTP code should I use when I can’t authenticate to third-party services with login and password provided by the client earlier?
I would go from 500. Explain. Think who’s integrating with your "A" API doesn’t care - from what I understand your question - about authentication for these internal Apis. The fact is that the user…
-
3
votes2
answers1024
viewsA: How to Sort List (Hibernate)
In JPQL, simply use ORDER BY followed by the variable name in your entity. Follow an example by situacao: public List<T> listarContas(String where) { String consulta = "FROM " +…
-
0
votes1
answer29
viewsA: Spring + Hibernate
The archive can stay in the directory WebContent/WEB-INF/. Other good options are WebContent/WEB-INF/classes/ or src.…
-
3
votes2
answers787
viewsA: What is elegant coding?
Excellent question. While this can bring several interpretations based on each developer’s professional experience, the final destination of an elegant code must meet some requirements that…
-
1
votes4
answers275
viewsA: API project with many layers
I’ll give you a hint of how you might have thought of this organization, which seems to me thought of as a SOA application: Api: used for Rest services. Appservices: used by Rest services. Contains…
-
4
votes1
answer3871
viewsA: Local Storage or Cookie, where is it best to store an authorization token?
Depends! With cookies, you don’t have to worry about sending the token to each request, as the browser takes care of this and other things like: send the cookie only to the domain in which it was…
-
2
votes3
answers1826
viewsA: Object search/registration via REST url and registration with SPRING
Are you trying to make an appointment by query param (clientes?nome=paulo) but implemented a search for path param. (clientes/paulo) Try changing your search to: @RequestMapping(method =…
-
7
votes2
answers2295
viewsA: Good Practices for URI in Restful API
If the project has activities, here is the correct way to represent, differentiating the PUT of PATCH. As I understand there will be the appeal /projetos/ and only the /atividades/ for GET, I will…
-
2
votes2
answers812
viewsA: Pegar sql Hibernate
You can create a appender specific to the Sqls log generated by Hibernate and have this log save the Sqls to a specific file. A different file will be generated per day, thanks to…
-
2
votes1
answer384
views -
2
votes2
answers96
viewsA: How to make Netbeans recognize the ES2015 syntax?
I believe that the current Netbeans IDE does not support Ecmascript 6 (Ecmascript 2015), but this is planned for the version 8.2 netbeans. If you’re willing, lower the development version Netbeans…
-
2
votes2
answers236
viewsA: How to find a pattern to maintain the same data modeling between a JSON, POJO, and JPA object?
Imagining that this JSON will be used in an API: 1 - In the examples with some fields works ok, but in a actual system, it is possible to maintain such standard in the 3 levels (json, java and bank)…
-
0
votes1
answer831
viewsA: Subquery in the select clause with JPA Criteria
JPA 2.0 can’t stand it sub-query in the SELECT clause. See if you can change your original SQL to get the same result without this sub-query. From there, it is easier to make an equivalent query…
-
4
votes1
answer201
views -
2
votes1
answer1147
viewsA: How to query in Manytomany tables?
The query seems to be incorrect, if you want to return the accessories too, in a single JPQL query. In this case, you need to use the FETCH. At first, I would write the consultation this way: SELECT…
-
3
votes3
answers3063
viewsA: Check whether "1" list value contains "2" list
track_list = ['iphone 6', 'iphone 5', 'moto x2', 'galaxy s6'] tweets_data = ['Eu queria um iphone 6 seriao', 'nao gostei do moto x2', 'iphone 5 e coisa do passado'] for tweet in tweets_data: for…
-
1
votes1
answer830
views -
4
votes1
answer593
viewsA: Using constructor and using set() for same attributes
Why does it use get and set? If the constructor already arrow such values when we define an object. [...] Maybe you shouldn’t just use get? The set is for updating the entity’s information, since it…